码迷,mamicode.com
首页 > 其他好文 > 详细

收集计算机分区信息

时间:2014-11-10 17:12:13      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   for   div   on   

以下脚本用来收集每台计算机的分区信息,并输出到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

 

收集计算机分区信息

标签:style   blog   io   color   os   sp   for   div   on   

原文地址:http://www.cnblogs.com/dreamer-fish/p/4087211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!