5

I'm trying to write a script that will audit shared folders on a few HIPAA-sensitive servers. I'm getting a list of shares just fine using gwmi Win32_Share, however when I go to get the permissions on each share using gwmi Win32_LogicalShareSecuritySetting, the hidden administrative shares are not listed.

I realize that's for obvious reasons, it's not like the permissions change, but I would like some kind of indication that this is in fact an administrative share. Currently I'm using a try-catch block to handle the error and kicking out a 'permissions could not be found' message.

Is there any way I can list ONLY hidden administrative shares using PowerShell?

1 Answer 1

4

Try (change "." to your remote computer name):

[String]                                   $Local:strComputerName  = ".";
[System.Management.ManagementBaseObject[]] $Local:arrShares        = @();
[System.Management.ManagementBaseObject]   $Local:objShare         = $null;

$arrShares = Get-WMIObject -class "Win32_Share" -namespace "root\CIMV2" -computername $strComputerName -ErrorAction SilentlyContinue | Where-Object { $_.Type -eq 2147483648 };
if ( $? ) {
    foreach ( $objShare in $arrShares ) {
        # List attributes (other attributes include AccessMask, AllowMaximum, Description,
        # InstallDate, MaximumAllowed, Status and Type).
        Write-Host -Object ( "Name        : {0}" -f $objShare.Name );
        Write-Host -Object ( "Path        : {0}" -f $objShare.Path );
        Write-Host -Object ( "Caption     : {0}" -f $objShare.Caption );
        Write-Host -Object "";
        } #foreach
} else {
    Write-Host -Object "ERROR.";
} #else-if
4
  • Ah, guess I should have been more clear. I need to list only administrative shares, so I can differentiate between those and hidden shares.
    – rtf
    Oct 4, 2013 at 20:38
  • Looks like adding -Filter "type=2147483648" to gwmi "Win32_Share" will display only admin shares. "type=0" will show only disk drive shares.
    – rtf
    Oct 4, 2013 at 20:52
  • Updated - see end of Get-WMIObject line... Oct 4, 2013 at 21:00
  • I tried this script and changed the "." to "HisComputer" and the console says "ERROR"
    – bgmCoder
    Feb 22, 2016 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .