0
I am trying to get a list of folders shared on a file server, and put them into an array. This is the code I have at the moment:
$FileServer = "ServerName"
[array]$FileServerShares = gwmi win32_Share -ComputerName $FileServer |
Where-Object {$_.type -eq '0'} |
Where {$_.name -notlike "*$*"}
Write-Host $FileServerShares
This outputs the folders that are shared (excluding the $ shares too), but the output puts them all into one long variable on one line.
How do I put this into an array with each record on a new line?
Update:
For those that are interested, I used the accepted answer and it worked great. I was actually after the "Name" instance of each folder, and so used code like this:
$FileServer = "ServerName"
$FileServerSharesFullName = gwmi win32_Share -ComputerName $FileServer |
Where-Object {$_.type -eq '0'} |
Where {$_.name -notlike "*$*"} # This excludes the "dollar shares" from being selected
$FileServerShares = $FileServerSharesFullName.name | % {$_.ToString()}
So each name of the folders that are shared in now in an array in $FileServerShares.
For anyone else looking to use strings in arrays, the next part of my code goes: