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, UserNameExamples
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, UserNameThe 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, FlagsProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AccessMask# | uint32 | read | 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)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | A short textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Comment# | string | read | Comment supplied by the network provider. Code | |||||||||||||||||||||||||||||||||||||||||||||
| ConnectionState# | string | read | Current state of the network connection. Values (6)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| ConnectionType# | string | read | Persistence type of the connection used for connecting to the network. Values (2)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| Description# | string | read | A textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||
| DisplayType# | string | read | Network object should be displayed in a network browsing user interface. Values (4)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Indicates when the object was installed. Lack of a value does not indicate that the object is not installed. Code | |||||||||||||||||||||||||||||||||||||||||||||
| LocalName# | string | read | Local name of the connected network device. Example: "c:\public" Code | |||||||||||||||||||||||||||||||||||||||||||||
| Name# key | string | read | Name of the current network connection. It is the combination of the values in RemoteName and LocalName. Example: "\\NTRELEASE (c:\public)" Code | |||||||||||||||||||||||||||||||||||||||||||||
| Persistent# | boolean | read | Connection will be reconnected automatically by the operating system on the next logon. Code | |||||||||||||||||||||||||||||||||||||||||||||
| ProviderName# | string | read | Name of the provider that owns the resource. This property can be NULL if the provider name is unknown. Code | |||||||||||||||||||||||||||||||||||||||||||||
| RemoteName# | string | read | 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 | |||||||||||||||||||||||||||||||||||||||||||||
| RemotePath# | string | read | Full path to the network resource. Example: "\\infosrv1\public" Code | |||||||||||||||||||||||||||||||||||||||||||||
| ResourceType# | string | read | Type of resource to enumerate or connect to. Values (3)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| Status# | string | read | 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)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| UserName# | string | read | User name or the default user name used to establish a network connection. Example: "SYSTEM" Code |
Remarks
The Win32_NetworkConnection class is derived from CIM_LogicalElement.
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- 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
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.