Author Posts

June 20, 2016 at 5:51 pm

When getting a list of shares, PowerShell responds with, "Cannot validate argument on parameter 'Path'. The argument is null or empty..."; happens on any system after the last drive share is listed (C$, D$, E$, etc.), while anything else is listed just fine.

$PSShareObject = Get-WmiObject -Class Win32_Share -Namespace 'root\CIMv2'

foreach($share in $PSShareObject)
        {
            $ShareName        = ($share).Name
            $SharePath        = ($share).Path
            $ShareDescription = ($share).Description
            $NTFSPermissions = (Get-Acl -Path $SharePath).AccessToString
            
            $Asset = New-Object -TypeName PSObject
            $Dictionary = [ordered]@{
                "Path"               = (Pad-Object $SharePath);
                "Description"        = (Pad-Object $ShareDescription);
                "NTFS Permissions"   = (Pad-Object $NTFSPermissions)
            }
        }

(Some code truncated to save time.)

Perhaps there is a more efficient way to do this... Would appreciate some input.

Thank you.

June 20, 2016 at 6:02 pm

Try a calculated property:

$PSShareObject = Get-WmiObject -Class Win32_Share -Namespace 'root\CIMv2' | 
Select *, @{Name="NTFS Permission";Expression={(Get-Acl -Path $_.Path).AccessToString}}

June 20, 2016 at 6:09 pm

Thanks Rob – getting the same results though.

FYI, the Pad-Object function just adds lines before and after the object. Using only your suggestion without Pad-Object returns the same error.

It's very odd that all other default shares, that are drives, do not have this error; only the last one listed. C$, Admin$, IPC$, etc. all list without the error. Tested systems: Windows 10 Pro, Server 2012 R2, Server 2008.