Powershell 在输出前修改 Select-Object 属性
Powershell Modify Select-Object Property Before Output
我如何从这个 Select-Object 的 DiskAllocation 属性 中删除前导的“{Storage consumed:,”和尾随的“}”以便仅保留大小?
例如:{消耗的存储空间:,48.62 MB}变为 48.62 MB
我知道我需要用正则表达式做一些替换语句,但我是 Powershell 的初学者。任何帮助将不胜感激。
$DS | Select-Object -Property Computer, Name, ObjectType, DiskAllocation | Format-Table -AutoSize | Out-String | Write-Host -ForegroundColor Cyan
当前输出如下所示:
从输出来看,DiskAllocation
属性 包含一个双项数组 - 您可以 select 只有第二项具有计算的 属性:
Select-Object -Property Computer, Name, ObjectType, DiskAllocation, @{Name='DiskAllocation';Expression={$_.DiskAllocation[1]}}
我如何从这个 Select-Object 的 DiskAllocation 属性 中删除前导的“{Storage consumed:,”和尾随的“}”以便仅保留大小?
例如:{消耗的存储空间:,48.62 MB}变为 48.62 MB
我知道我需要用正则表达式做一些替换语句,但我是 Powershell 的初学者。任何帮助将不胜感激。
$DS | Select-Object -Property Computer, Name, ObjectType, DiskAllocation | Format-Table -AutoSize | Out-String | Write-Host -ForegroundColor Cyan
当前输出如下所示:
从输出来看,DiskAllocation
属性 包含一个双项数组 - 您可以 select 只有第二项具有计算的 属性:
Select-Object -Property Computer, Name, ObjectType, DiskAllocation, @{Name='DiskAllocation';Expression={$_.DiskAllocation[1]}}