以下脚本用来收集每台计算机的分区信息,并输出到CSV。
1 $servers = gc D:\serverlist.txt 2 $result = $results = $null 3 $results = @() 4 foreach ($server in $servers) 5 { 6 If ($server -eq "10") 7 $UserName = "administrator" 8 $serverpass ="abcd" 9 $Password = ConvertTo-SecureString $serverpass -AsPlainText –Force 10 $cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) 11 12 $disks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $server -Credential $cred -Filter "DriveType=3" 13 foreach ($disk in $disks) 14 { 15 $result = ""|Select Server,DeviceID,FreeSize,TotalSize,Free_Percentage 16 $result.Server = $server 17 $result.DeviceID = $disk.deviceid 18 $result.FreeSize = ($disk.freespace/1GB).tostring("f1") 19 $result.TotalSize = ($disk.size/1GB).tostring("f1") 20 $result.Free_Percentage = "{0:p}" -f ($disk.freespace / $disk.size) 21 $results += $result 22 } 23 } 24 $results |export-csv D:\disks.csv -Encoding default -NoTypeInformation
时间: 2024-11-10 16:01:08