Hi,
I am unable get the output from below script from the vm remotely. please help.
If I execute the command directly on the vm, I get the desired output but i am unable to get the output from grep command in the output
please help!!
$script = @"
GREEN=$'\e[0;32m'
RED=$'\e[0;31m'
NC=$'\e[0m'
echo ""
echo "${GREEN}Checking centrifydc.conf for 3 parameters exists :: account1 - account2 - account3"
echo ""
grep -n -i "account1\|account2\|account3" --color=always /etc/centrifydc/centrifydc.conf
echo ""
echo ""
echo "${GREEN}Checking sudoers file for 4 parameters exists :: account1 - account2 - account3 - #Defaults requiretty"
echo ""
grep -n -i "account1\|account2\|%account3\|#Defaults requiretty" --color=always /etc/sudoers
"@
$Username = 'root'
$pass = ConvertTo-SecureString -AsPlainText 'password' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Import-Csv -Path "D:\MyVM.csv" -UseCulture -PipelineVariable row |
ForEach-Object -Process {
try {
$session = New-SSHSession "192.168.1.100" -Credential $Cred -AcceptKey -ErrorAction Stop
$connected = $session.Connected
$result = Invoke-SSHCommand -SSHSession $session -Command $script -Verbose
$result.Output.Replace("`r`n",'|').Split('|').Where{$_ -ne ''}
Remove-SSHSession $session -Verbose | Out-Null
}
catch {
$connected = $false
$result = ''
}
}
I am getting the output from echo command but not from grep command