从 csv 获取输入时如何处理表达式
How to handle an expression when input is taken from a csv
powershell 初学者并寻求有关@{Label='ID' 的帮助; expression={??} 部分请:-
$ID = @()
Import-Csv C:\computers2.csv | ForEach-Object {$ID += $_.ID}
Get-WmiObject -Class Win32_LogicalDisk -ComputerName $ID |
Select-Object -Property DeviceID, @{Label='ID'; expression=
{$ID}},
@{Label='Total (Gb)'; expression={($_.Size/1GB).ToString('F2')}},
@{Label='Free (Gb)'; expression=
{($_.FreeSpace/1GB).ToString('F2')}},
@{label='Percent'; expression={[Math]::Round(($_.freespace /
$_.size) * 100, 2)}} | Format-Table
我得到的输出是这样的:-
output
我想要实现的是:-
desired output
在遵循一些指南并获得正确的变量后设法解决了这个问题
$CSV = Import-Csv C:\computers.csv
$SPACE = ForEach ($ID in $CSV) {
Get-WmiObject -Class Win32_LogicalDisk -ComputerName ($ID.ID) |
Select-Object -Property DeviceID,
@{Label='ID'; expression={$_.SystemName}},
@{Label='Total (Gb)'; expression={($_.Size/1GB).ToString('F2')}},
@{Label='Free (Gb)'; expression={($_.FreeSpace/1GB).ToString('F2')}},
@{Label='PercentFree'; expression={[Math]::Round(($_.freespace / $_.size) *
100, 2)}}
} | FormatTable
powershell 初学者并寻求有关@{Label='ID' 的帮助; expression={??} 部分请:-
$ID = @()
Import-Csv C:\computers2.csv | ForEach-Object {$ID += $_.ID}
Get-WmiObject -Class Win32_LogicalDisk -ComputerName $ID |
Select-Object -Property DeviceID, @{Label='ID'; expression=
{$ID}},
@{Label='Total (Gb)'; expression={($_.Size/1GB).ToString('F2')}},
@{Label='Free (Gb)'; expression=
{($_.FreeSpace/1GB).ToString('F2')}},
@{label='Percent'; expression={[Math]::Round(($_.freespace /
$_.size) * 100, 2)}} | Format-Table
我得到的输出是这样的:-
output
我想要实现的是:-
desired output
在遵循一些指南并获得正确的变量后设法解决了这个问题
$CSV = Import-Csv C:\computers.csv
$SPACE = ForEach ($ID in $CSV) {
Get-WmiObject -Class Win32_LogicalDisk -ComputerName ($ID.ID) |
Select-Object -Property DeviceID,
@{Label='ID'; expression={$_.SystemName}},
@{Label='Total (Gb)'; expression={($_.Size/1GB).ToString('F2')}},
@{Label='Free (Gb)'; expression={($_.FreeSpace/1GB).ToString('F2')}},
@{Label='PercentFree'; expression={[Math]::Round(($_.freespace / $_.size) *
100, 2)}}
} | FormatTable