I have the below script which needs to be ran against multiple servers in the servers.txt file , tried few things with Invoke command but not able to get the entire script working.
Any ideas are much apprecaited!
$ServerNames = get-content "c:\Temp\servers.txt"
foreach ($servername in $servernames)
{
$servername
$AAClientVersion = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |Get-ItemProperty | where-Object DisplayName -eq "AA 11.3"
If ($AAClientVersion.DisplayVersion -eq "11.3.4.2") {
write-host $AAClientVersion.DisplayName "Current Version is $($AAClientVersion.DisplayVersion )" -BackgroundColor DarkGreen
}
Else {
write-host $AAClientVersion.DisplayName 'Different version exists,Check Version!' -BackgroundColor Red -ErrorAction stop
}
$process = Get-Process 'aa' -ErrorAction SilentlyContinue
if ($process -eq $true) {
write-warning "Stopping process aa"
Stop-process -processname 'aa'
}
elseif($process -eq $null){
Write-warning "process aa is not running"
}
write-warning "Stopping service AA"
Get-Service -DisplayName 'AA*' -ErrorAction Silentlycontinue
Stop-Service -DisplayName 'AA*'
write-warning "AA service is stopped successfully"