是否可以通过PowerShell脚本将所有磁盘,驱动器和安装点详细信息(包括名称,可用空间和容量)导出到csv文件中。
$serverlist = Get-Content .\servers.txt
Write-Output "disk details"
foreach ($server in $serverlist) {
$a = Get-WmiObject Win32_Volume -ComputerName $server
foreach ($drive in $a) {
$b = $a.Name
$c = $a.Label
$d = $a.FreeSpace
$e = $a.Capacity
}
Write-Output "$server, $b, $c, $d, $e " | Out-File C:\EAM\ram.csv -Append
}
CSV文件应采用以下格式:
Server Name Disk Name FreeSpace Capacity Server1 Disk1 X GB Y GB Disk2 A GB B GB Server 2 Disk 1 C GB D GB Disk 5 Z GB N GB ... ... ... ...
答案 0 :(得分:0)
您太复杂了。这将满足您的要求:
$serverlist = Get-Content .\servers.txt
Get-WmiObject Win32_Volume -Computer $serverlist |
Select-Object __SERVER, Name, Label, FreeSpace, Capacity |
Export-Csv 'C:\output.csv' -NoType
如果您需要特定的列标题而不是常规的属性名称或特定格式的值,请使用calculated properties进行更改:
Get-WmiObject Win32_Volume -Computer $serverlist |
Select-Object @{n='Server Name';e={$_.__SERVER}}, @{n='Drive';e={$_.Name}},
@{n='Disk Name';e={$_.Label}},
@{n='FreeSpace';e={'{0} GB' -f [int]($_.FreeSpace/1GB)}},
@{n='Capacity';e={'{0} GB' -f [int]($_.Capacity/1GB)}} |
Export-Csv 'C:\output.csv' -NoType