I am trying to get a list of SMB shares on a remote file server. Unfortunately because of the type of server I am querying WMI and CIM won't work. The only thing I can get to work is net view (which I believe uses netbios).
I am running the following code which gets the shares:
$shares = net view \\server1 /all | select -Skip 7 | ?{$_ -match 'disk*'} | %{$_ -match '^(.+?)\s+Disk*'|out-null;"\\server1\$($matches[1])"}
$shares += net view \\server2 /all | select -Skip 7 | ?{$_ -match 'disk*'} | %{$_ -match '^(.+?)\s+Disk*'|out-null;"\\server2\$($matches[1])"}
foreach ($share in $shares) {
$logdir1 = @("$share\App_Data\","errorlogs")
$logdirs = @($logdir1)
foreach ($log in $logdirs) {
write-host $log[0]
However, instead of getting a list of paths, I am getting the first character of each path. So basically $log[0] is a character - not a string as I an expecting.
I think this has to do with the net view command returning characters instead of an object.
I tried using ToString()
in various places to no avail. Anyone help me figure out how to get this to work?
Thanks!