[英]PowerShell script to Export all the disk and drive details (Including mount point) along with name, freespace and capacity to a CSV file
Is there a way to get PowerShell script to export all disk, drive and mount point details (including name, freespace and capacity) to a csv file. 有没有一种方法可以使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
}
The CSV file should be in the below format: 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 ... ... ... ...
You're overcomplicating things. 您太复杂了。 This will do what you want:
这将做您想要的:
$serverlist = Get-Content .\servers.txt
Get-WmiObject Win32_Volume -Computer $serverlist |
Select-Object __SERVER, Name, Label, FreeSpace, Capacity |
Export-Csv 'C:\output.csv' -NoType
If you need particular column titles instead of the regular property names or values in a particular format use calculated properties to change that: 如果您需要特定的列标题而不是常规的属性名称或特定格式的值,请使用计算所得的属性来更改该属性 :
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.