Default Share - Path Error on Last Drive Listed

Welcome Forums General PowerShell Q&A Default Share - Path Error on Last Drive Listed

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 10 months ago.

  • Author
  • #44001

    Points: 34
    Rank: Member

    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

    Points: 639
    Helping Hand
    Rank: Major Contributor

    Try a calculated property:

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

    Points: 34
    Rank: Member

    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.

The topic ‘Default Share - Path Error on Last Drive Listed’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort