对,我有一个 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,Gateway
PC1,Microsoft.Powershell.Commands.Internal.Format.FormatStartData PC2,Microsoft.Powershell.Commands.Internal.Format.FormatStartData
在这里的任何帮助将不胜感激,我不知道我做了什么导致这个......
谢谢,