Inventory files on multiple servers
i have script runs fine on local system.
displays inventory of files on server , exports csv-file (per drive)
$clustersize=4096
$afz=[midpointrounding]::awayfromzero
$mydrives=get-psdrive | where-object {$_.provider.name -eq "filesystem"} | select root, name
$strtemppath = "c:\temp"
if (!(test-path $strtemppath))
{
new-item -itemtype directory -force -path $strtemppath
}
foreach ($drive in $mydrives) {
$strdrive=$drive.name
$strhost=$env:computername
$strexportfilename = "$strtemppath\files-$strhost-$strdrive.csv"
gci $drive.root -recurse| where-object {-not $_.psiscontainer} | select directoryname, name, extension, length, @{name="sizeondisk";expression={[math]::round($_.length/$clustersize+0.5,$afz)*$clustersize}}, @{name="hostname";expression={$env:computername}}, @{name="psdrive";expression={$drive.root}} | export-csv $strexportfilename
}
i want collect information multiple servers.
added servers host.txt file ($servers = server.txt) , added additional foreach ($server in $servers)
not work, still wants gather information locally.
how can accomplish this?
just use wmi space - freespace more accurate trying do. use of many scripts in gallery.
get-wmiobject win32_volume -filter 'drivetype=3' -computer $server| select capacity, freespace, @{n='used';e={$_.capicity - $_.freespace}}
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment