首页 > 代码库 > 收集计算机分区信息

收集计算机分区信息

以下脚本用来收集每台计算机的分区信息,并输出到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 –Force10  $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_Percentage16      $result.Server = $server17      $result.DeviceID = $disk.deviceid18      $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 += $result22     }23 }24  $results |export-csv  D:\disks.csv -Encoding default -NoTypeInformation

 

收集计算机分区信息