0
我得到CSV格式的磁盤的詳細信息在Windows Server
大家好我想在下面的格式細節如何使用PowerShell
Hostname Drive_0 Drive_1 Drive_2
Name C: 99.899227142334 d: 99.899227142334 e: 99.899227142334
我可以用下面的腳本得到這個細節,但這個工程上的PowerShell 3.0 我如何更改爲在PowerShell 2.0上執行
$result = @()
$obj = new-object PSobject
$server = hostname
$obj |Add-Member -MemberType NoteProperty -Name "Hostname" -Value $server -ErrorAction SilentlyContinue
$z = Get-WmiObject -Class win32_Logicaldisk -Filter 'DriveType=3' | Select-Object -Property DeviceID, @{LABEL='TotalSize';EXPRESSION={$_.Size/1GB}}
$z3 = $z.DeviceID
$z4 = $z.TotalSize
$i = 0
foreach($z3 in $z3){
$z1 = $z.DeviceID[$i]
$z2 = $z.TotalSize[$i]
$zx = "$z1" + ": $z2"
$obj | Add-Member -MemberType NoteProperty -Name "Drive_$i" -Value $zx -ErrorAction SilentlyContinue
$i++
}
$result+=$obj
$result | Export-Csv "$env:userprofile\Desktop\Result.csv" -NoTypeInformation
在PowerShell 2.0上運行時會出現什麼錯誤? – Richard 2014-09-24 11:18:57
您是否偶然在運行2.0的計算機上只有一個磁盤出現此錯誤? '無法索引到System.Double類型的對象' – Matt 2014-09-24 12:19:31
完美馬特..我得到同樣的錯誤 – Chand 2014-09-24 12:29:07