Converting the FileSystemObject's ShareName Property
Definition: Given a Drive, returns the name of the network share.
We’re going to take the easy way out on this one and simply use the FileSystemObject from within PowerShell:
$a = New-Object -ComObject Scripting.FileSystemObject $d = $a.GetDrive("Z:\") $d.ShareName
Here we’re creating an instance of the FileSystemObject by passing it with the -ComObject parameter to the New-Object cmdlet. We then get the drive that’s mapped to a network share by calling the GetDrive method. After that all we have to do is display the ShareName property.