如果我安装了一些应用程序,现在脚本返回txt文件结果,我使用此脚本检查多台计算机。(格式主机名\n是/否)。我如何更改返回结果在csv文件中的2列; 1.主机名; 2.结果如何?
actual result.txt
hostname
YES / NO
desired csv export
Hostname | Result
hostname | YES / NO / OFFLINE
脚本
$Computers = Get-Content -Path C:\Users\m\Desktop\ip.txt | Where-Object { $_ -match '\S' }
foreach($Computer in $Computers){
Write-Host $Computer
$User = "ussr"
$Password = "pssd"
$Command = 'hostname && if exist "C:\LdApp.exe" (echo YES) else (echo NO)'
$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd)
Get-SSHTrustedHost | Remove-SSHTrustedHost
try{
$SessionID = New-SSHSession -ComputerName $Computer -Credential $Credentials -AcceptKey:$true
Invoke-SSHCommand -Index $sessionid.sessionid -Command $Command | Select -Expand Output | Add-Content -Path result.txt}
catch {Add-Content -Path result.txt -Value "$Computer conectare esuata!"}
}
谢谢你,
1条答案
按热度按时间2vuwiymt1#
我已经修改了你的代码,但没有测试它。我会做一些这样的事情
**Answer2:**用于多个命令和捕获结果,但仍未测试:(