I am trying to get the share files from servers into a .txt, by using net view \\server_name /all
command on the cmd gives me what I want , but there are several hundred servers, can I do this using a batch file
or I could use net view
on a .txt
file with all servers listed on it.
I came across this code but it is again for a single server, can it be modified to be used for a .txt
file
# List the file shares on the remote server: SERVER64.
$shares = Get-WmiObject -class Win32_Share -computername SERVER64 -filter "Type=0"
$shares | foreach {
$path=($_.path)
$Description=($_.Description)
$name=($_.name)
$Caption=($_.Caption)
"Share Name : $name
Source Folder: $path
Description : $Description
Caption : $Caption"
}
I agree with lit, but here a script along your sample with a [PSCustomObject]
## Q:\Test\2018\10\25\SO_52991906.ps1
$ServerShares = ForEach ($Server in (Get-Content .\Servers.txt)){
ForEach ($Share in (Get-WmiObject -Class Win32_Share -Computername $Server -filter "Type=0"|
Select-Object Name,Path,Description,Caption)){
[PSCustomObject]@{
Server = $Server
'Share Name' = $Share.Name
'Source Folder' = $Share.Path
Description = $Share.Description
Caption = $Share.Caption
}
}
}
$ServerShares | Format-Table -auto
#$ServerShares | Out-GridView
#$ServerShares | Export-Csv .\ServerShares.csv -NoTypeInformation
Sample output
> Q:\Test\2018\10\25\SO_52991906.ps1
Server Share Name Source Folder Description Caption
------ ---------- ------------- ----------- -------
ServX C C:\ System System
ServX D D:\ Daten Daten
ServX G G:\ G
ServX H H:\ H
ServX print$ C:\Windows\system32\spool\drivers Druckertreiber Druckertreiber
ServX LotPings D:\Home\LotPings LotPings
ServX Users C:\Users Users
ServX Virtual D:\Virtual Virtual
ServX Winstall D:\Winstall Winstall
ServX X X:\ X
ServX Y$ Y:\ Standardfreigabe Standardfreigabe
ServX Z$ Z:\ Standardfreigabe Standardfreigabe