首页 > 代码库 > 收集计算机分区信息
收集计算机分区信息
以下脚本用来收集每台计算机的分区信息,并输出到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
收集计算机分区信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。