I use the following script to gather data from all of our linux servers in the enterprise. Another app normalizes all of the harvested files into a single multi tabbed Excel spreadsheet.
Import-Module SSH-Sessions
$servers = Import-Csv C:\Automate\bin\Servers.csv
ForEach ($S in $Servers)
{
$I = $S.Address; Write-host $I
$H = $S.Hostname; Write-host $H
$K = $S.key; Write-host $K
$U = $S.user; Write-host $U
If (test-path C:\Automate\Results\$H) {Write-host "Folder Already Exists" -verbose} else {New-Item -ItemType directory -Path C:\ISCO\Automate\Results\$H -Verbose}
New-SshSession -ComputerName $I -Username $U -KeyFile $K
Invoke-SshCommand -ComputerName $I -Command "sudo cat /etc/passwd" | Out-File C:\Automate\Results\$H\$H-passwd.txt
Invoke-SshCommand -ComputerName $I -Command "sudo cat /etc/shadow" | Out-File C:\Automate\Results\$H\$H-shadow.txt
Invoke-SshCommand -ComputerName $I -Command "sudo cat /var/ossec/etc/ossec.conf" | Out-File C:\Automate\Results\$H\$H-ossec.conf.txt
Invoke-SshCommand -ComputerName $I -Command "sudo cat /var/ossec/etc/shared/agent.conf" | Out-File C:\Automate\Results\$H\$H-agent.conf.txt
Invoke-SshCommand -ComputerName $I -Command "sudo yum check-update --security --enablerepo=epel" -Verbose | Out-File C:\Automate\Results\$H\$H-updateStatus.txt -Append
#Invoke-SshCommand -ComputerName $I -Command "sudo /var/ossec/bin/ossec-control restart"
Remove-SshSession $I
}
Each time that the script iterates through line 17 ("sudo yum check-update --security --enablerepo=epel") I receive the following error:
x.x.x.x had an error:
When I run the command from the command line, I receive the same error.
PS C:\Users\Administrator> Invoke-SshCommand -ComputerName $I -Command "sudo yum check-update --security" -Verbose
x.x.x.x had an error:
When I run each of the following commands from the command line on the Linux Server, I receive the desired output reliably.
sudo yum check-update
sudo yum check-update --security
sudo yum check-update --security --enablerepo=epel
I would like to accomplish two things:
1. Have the command output the data like all of the other statements that seem to work fime
2. determine how to obtain more data from the error message "IP.IP.IP.IP had an error:" as "-Verbose" does not seem to help much.
I appreciate the assistance.
Jared