Default Share - Path Error on Last Drive Listed

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Aaron Hardy Aaron Hardy 5 months, 2 weeks ago.

  • Author
    Posts
  • #44001
    Profile photo of Aaron Hardy
    Aaron Hardy
    Participant

    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.

  • #44005
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Try a calculated property:

    $PSShareObject = Get-WmiObject -Class Win32_Share -Namespace 'root\CIMv2' | 
    Select *, @{Name="NTFS Permission";Expression={(Get-Acl -Path $_.Path).AccessToString}}
    
  • #44007
    Profile photo of Aaron Hardy
    Aaron Hardy
    Participant

    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.

You must be logged in to reply to this topic.