Recipes by topic

Network shares of a computer

Win32_Share lists the shares exposed by the Server service: shares created by users, but also administrative shares (C$, ADMIN$, IPC$).

Get-CimInstance -ClassName Win32_Share |
    Select-Object -Property @(
        'Name'
        'Path'
        'Description'
        'Type'
        @{ Name = 'Administrative'; Expression = { $_.Type -ge 2147483648 } }
    ) |
    Sort-Object -Property Name

Type is 0 for a shared folder and 1 for a printer. Values from 2147483648 (high bit) are administrative shares, which the Administrative column shows.

Variant: remote

The Type = 0 filter keeps only non-administrative shared folders. The Create and Delete methods of the class create and remove shares: they change the system and are not used here.

$cimSession = New-CimSession -ComputerName 'SERVER01', 'SERVER02'
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = 'Win32_Share'
        Filter     = 'Type = 0'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property PSComputerName, Name, Path |
        Sort-Object -Property PSComputerName, Name
} finally {
    Remove-CimSession -CimSession $cimSession
}

Classes used

← All recipes