格式化变量 Table 的输出 - 在 PowerShell 中查看
Format output from Variables Table-View in PowerShell
从 CSV 文件中检索信息。
我这样存储值:
Foreach($FlexVPN in $FlexVPNlist) {
# Number of pings
$Ping = $FlexVPN.'Priority'
$Test = New-Variable -Name $FlexVPN.'IP-adress' -Value (New-Object PSObject -Property @{
IP = $FlexVPN.'IP-adress'
Information = $FlexVPN.'Information'
Priority = $FlexVPN.'Priority'
ResponseTime = $Result = Test-Connection -ComputerName $FlexVPN.'IP-adress' -Count $FlexVPN.'Priority' -ea silentlycontinue | Select ResponseTime})
我想在代码中输出 window 表格视图中的信息。
使用Write-Host $FlexVPN.'IP-adress' "," $FlexVPN.'Information' "," $FlexVPN.'Priority' "," $Result.ResponseTime
给我数据,但不是我想要的结构。
在tableview中如何格式化?
为此使用 PSCustomObject:
[PSCustomObject]@{
"IP address" = $FlexVPN.'IP-adress'
"Information" = $FlexVPN.'Information'
"Priority" = $FlexVPN.'Priority'
"Response time" = $Result.ResponseTime
}
从 CSV 文件中检索信息。 我这样存储值:
Foreach($FlexVPN in $FlexVPNlist) {
# Number of pings
$Ping = $FlexVPN.'Priority'
$Test = New-Variable -Name $FlexVPN.'IP-adress' -Value (New-Object PSObject -Property @{
IP = $FlexVPN.'IP-adress'
Information = $FlexVPN.'Information'
Priority = $FlexVPN.'Priority'
ResponseTime = $Result = Test-Connection -ComputerName $FlexVPN.'IP-adress' -Count $FlexVPN.'Priority' -ea silentlycontinue | Select ResponseTime})
我想在代码中输出 window 表格视图中的信息。
使用Write-Host $FlexVPN.'IP-adress' "," $FlexVPN.'Information' "," $FlexVPN.'Priority' "," $Result.ResponseTime
给我数据,但不是我想要的结构。
在tableview中如何格式化?
为此使用 PSCustomObject:
[PSCustomObject]@{
"IP address" = $FlexVPN.'IP-adress'
"Information" = $FlexVPN.'Information'
"Priority" = $FlexVPN.'Priority'
"Response time" = $Result.ResponseTime
}