是的,我有一个Powershell脚本,如下所示:
Function GatewayScan
{
cls
$CNList = Import-Csv "c:\Users\user\desktop\scans\ComputerList.csv"
"MachineName, GatewayAddress" | out-file "C:\Users\user\desktop\scans\GatewayList.txt" -append -noClobber
foreach ($line in $CNList) {
IF (test-connection -comp $($line.machinename) -count 1 -quiet) {
Write-Host "Geting Gateway for " $($line.machinename)
$gate = get-wmiobject -cn $($line.machinename) win32_networkadapterconfiguration | where {$_.IPEnabled -eq "TRUE"} | select DefaultIPGateway | format-list
$($line.machinename) + "," + $gate | out-file "C:\Users\user\desktop\scans\GatewayList.txt" -append -noClobber
}
Else {
$($line.machinename) + ", Offline" | out-file "C:\Users\user\desktop\scans\GatewayList.txt" -append -noClobber
}
}
}
当我运行它时,它会循环通过机器,并拉出默认网关信息。然后它将此信息以及机器名称写入csv。问题是,当我操作它产生的文本文件时,我得到的东西看起来像这样:
MACHINENAME,网关
PC1,Microsoft.Powershell.Commands.Internal.Format.FormatStartData PC2,Microsoft.Powershell.Commands.Internal.Format.FormatStartData
任何帮助都会受到赞赏,我不知道我做了什么导致这个......
谢谢,
答案 0 :(得分:1)
将管道移至Format-List
,它会生成格式说明。此外,请确保通过展开属性来获取DefaultIPGateway的原始值:
... | select -expand DefaultIPGateway