Win32_NetworkConnection

Win32 Network Connection
root/cimv2dynamickey : Name

Represents an active network connection in a Windows-based environment.

On this page

Main example

List instances

# All instances of Win32_NetworkConnection, with the main properties
Get-CimInstance -ClassName Win32_NetworkConnection |
    Select-Object -Property Name, Description, Status, InstallDate, UserName

Examples

Filter with WQL

# WQL filter evaluated by the provider: AccessMask = 1 (FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory))
Get-CimInstance -ClassName Win32_NetworkConnection -Filter 'AccessMask = 1' |
    Select-Object -Property Name, Description, Status, InstallDate, UserName

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Decode numeric values

# Lookup table for AccessMask (values documented by Microsoft)
$accessMaskName = @{
    1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
    2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
    4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'
    8 = 'FILE_READ_EA'
    16 = 'FILE_WRITE_EA'
    32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
    64 = 'FILE_DELETE_CHILD (directory)'
    128 = 'FILE_READ_ATTRIBUTES'
    256 = 'FILE_WRITE_ATTRIBUTES'
    65536 = 'DELETE'
    131072 = 'READ_CONTROL'
    262144 = 'WRITE_DAC'
    524288 = 'WRITE_OWNER'
    1048576 = 'SYNCHRONIZE'
}

Get-CimInstance -ClassName Win32_NetworkConnection |
    Select-Object -Property @(
        'Name'
        'Description'
        'Status'
        'InstallDate'
        'UserName'
        @{ Name = 'AccessMask'; Expression = { $accessMaskName[[int]$_.AccessMask] } }
    )

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_NetworkConnection |
        Select-Object -Property Name, Description, Status, InstallDate, UserName
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_NetworkConnection
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

17 of 17 properties
NameTypeAccessDescription
AccessMaskuint32read

List of access rights to the given file or directory held by the user or group on whose behalf the instance is returned. On FAT volumes, the FULL_ACCESS value is returned instead, indicating no security has been set on the object.

Values (14)
ValueLabelDescription
1FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)Grants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory.
2FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)Grants the right to write data to the file. For a directory, this value grants the right to create a file in the directory.
4FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORYGrants the right to append data to the file. For a directory, this value grants the right to create a subdirectory.
8FILE_READ_EAGrants the right to read extended attributes.
16FILE_WRITE_EAGrants the right to write extended attributes.
32FILE_EXECUTE (file) or FILE_TRAVERSE (directory)Grants the right to execute a file. For a directory, the directory can be traversed.
64FILE_DELETE_CHILD (directory)Grants the right to delete a directory and all of the files it contains (its children), even if the files are read-only.
128FILE_READ_ATTRIBUTESGrants the right to read file attributes.
256FILE_WRITE_ATTRIBUTESGrants the right to change file attributes.
65536DELETEGrants delete access.
131072READ_CONTROLGrants read access to the security descriptor and owner.
262144WRITE_DACGrants write access to the discretionary access control list (DACL).
524288WRITE_OWNERAssigns the write owner.
1048576SYNCHRONIZESynchronizes access and allows a process to wait for an object to enter the signaled state.
Code
# Value of AccessMask for each instance
# Lookup table for AccessMask (values documented by Microsoft)
$accessMaskName = @{
    1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
    2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
    4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'
    8 = 'FILE_READ_EA'
    16 = 'FILE_WRITE_EA'
    32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
    64 = 'FILE_DELETE_CHILD (directory)'
    128 = 'FILE_READ_ATTRIBUTES'
    256 = 'FILE_WRITE_ATTRIBUTES'
    65536 = 'DELETE'
    131072 = 'READ_CONTROL'
    262144 = 'WRITE_DAC'
    524288 = 'WRITE_OWNER'
    1048576 = 'SYNCHRONIZE'
}
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, AccessMask |
    Select-Object -Property @(
        'Name'
        @{ Name = 'AccessMask'; Expression = { $accessMaskName[[int]$_.AccessMask] } }
    )
Captionstringread

A short textual description of the object.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, Caption |
    Select-Object -Property Name, Caption
Commentstringread

Comment supplied by the network provider.

Code
# Value of Comment for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, Comment |
    Select-Object -Property Name, Comment
ConnectionStatestringread

Current state of the network connection.

Values (6)
ValueLabelDescription
ConnectedConnected
ErrorError
PausedPaused
DisconnectedDisconnected
ConnectingConnecting
ReconnectingReconnecting
Code
# Value of ConnectionState for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, ConnectionState |
    Select-Object -Property Name, ConnectionState
ConnectionTypestringread

Persistence type of the connection used for connecting to the network.

Values (2)
ValueLabelDescription
Current ConnectionCurrent Connection
Persistent ConnectionPersistent Connection
Code
# Value of ConnectionType for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, ConnectionType |
    Select-Object -Property Name, ConnectionType
Descriptionstringread

A textual description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, Description |
    Select-Object -Property Name, Description
DisplayTypestringread

Network object should be displayed in a network browsing user interface.

Values (4)
ValueLabelDescription
DomainDomain
GenericGeneric
ServerServer
ShareShare
Code
# Value of DisplayType for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, DisplayType |
    Select-Object -Property Name, DisplayType
InstallDatedatetimeread

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, InstallDate |
    Select-Object -Property Name, InstallDate
LocalNamestringread

Local name of the connected network device.

Example: "c:\public"

Code
# Value of LocalName for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, LocalName |
    Select-Object -Property Name, LocalName
Name keystringread

Name of the current network connection. It is the combination of the values in RemoteName and LocalName.

Example: "\\NTRELEASE (c:\public)"

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name |
    Select-Object -Property Name
Persistentbooleanread

Connection will be reconnected automatically by the operating system on the next logon.

Code
# Value of Persistent for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, Persistent |
    Select-Object -Property Name, Persistent
ProviderNamestringread

Name of the provider that owns the resource. This property can be NULL if the provider name is unknown.

Code
# Value of ProviderName for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, ProviderName |
    Select-Object -Property Name, ProviderName
RemoteNamestringread

Remote network resource name for a network resource. For a current or persistent connection, RemoteName contains the network name associated with the name of the value in the LocalName property. The name in RemoteName must follow the network provider's naming conventions.

Example: "\\NTRELEASE"

Code
# Value of RemoteName for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, RemoteName |
    Select-Object -Property Name, RemoteName
RemotePathstringread

Full path to the network resource.

Example: "\\infosrv1\public"

Code
# Value of RemotePath for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, RemotePath |
    Select-Object -Property Name, RemotePath
ResourceTypestringread

Type of resource to enumerate or connect to.

Values (3)
ValueLabelDescription
DiskDisk
PrintPrint
AnyAny
Code
# Value of ResourceType for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, ResourceType |
    Select-Object -Property Name, ResourceType
Statusstringread

String that indicates the current status of the object. Operational and non-operational status can be defined. Operational status can include "OK", "Degraded", and "Pred Fail". "Pred Fail" indicates that an element is functioning properly, but is predicting a failure (for example, a SMART-enabled hard disk drive).

Non-operational status can include "Error", "Starting", "Stopping", and "Service". "Service" can apply during disk mirror-resilvering, reloading a user permissions list, or other administrative work. Not all such work is online, but the managed element is neither "OK" nor in one of the other states.

Values include the following:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, Status |
    Select-Object -Property Name, Status
UserNamestringread

User name or the default user name used to establish a network connection.

Example: "SYSTEM"

Code
# Value of UserName for each instance
Get-CimInstance -ClassName Win32_NetworkConnection -Property Name, UserName |
    Select-Object -Property Name, UserName

Remarks

The Win32_NetworkConnection class is derived from CIM_LogicalElement.

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. Win32_NetworkConnection

Known subclasses

No known subclass.

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") UUID("{8502C4CD-5FBB-11D2-AAC1-006008C78BC7}") AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.