Hello
Some help please, the code below works apart from the running of the application I have tried many variations the current one the working directory cannot be found. But other instances produce access denied or the code completes but nothing happens on the machine. I have really new to powershell so any help with tidying up my code as well as getting the running of the program would be great.
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process NTRmv.exe -WorkingDirectory "%programfiles(x86)%\Trend Micro\OfficeScan Client"}
I have tried
$Computers = Get-content "C:\Comps.txt"
$Cred = Get-Credential ""
$RegKey = “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc.”
$Name = "Allow Uninstall"
$Type = "DWord"
$value = "1"
ForEach($computer in $computers)
{
If(Test-Connection -ComputerName $computer -BufferSize 16 -count 1 -Quiet)
{
Get-Service remoteregistry -ComputerName $computer | Start-Service
$service1 = Get-service "ntrtscan" -ComputerName $computer -ErrorAction SilentlyContinue
$service2 = Get-service "tmccsf" -ComputerName $computer -ErrorAction SilentlyContinue
$service3 = Get-service "tmlisten" -ComputerName $computer -ErrorAction SilentlyContinue
$Service4 = Get-service "winrm" -ComputerName $computer -ErrorAction SilentlyContinue
Invoke-Command -ComputerName $computer -ScriptBlock {Set-ExecutionPolicy Unrestricted -Force}
If ($service1 –eq $null –or $service1.status –eq “Stopped”)
{
Write-host $($computer + ' Service has already stopped or does not exist') -BackgroundColor Red
}
else
{
$Service1 | Stop-Service -Force -ErrorAction Continue
}
If ($service2 –eq $null –or $service2.status –eq “Stopped”)
{
Write-host $($computer + ' Service has already stopped or does not exist') -BackgroundColor Red
}
else
{
$Service2 | Stop-Service -Force -ErrorAction Continue
}
if ($service3 –eq $null –or $service3.status –eq “Stopped”)
{
Write-host $($computer + ' Service has already stopped or does not exist') -BackgroundColor Red
}
else
{
$Service3 | Stop-Service -Force -ErrorAction Continue
}
If ($service4 -eq $null –or $service4.status –eq “Running”)
{
Write-host $($computer + ' Service has already started') -BackgroundColor Red
}
else
{
$service4 | Start-Service -ErrorAction SilentlyContinue
}
$s = New-PSSession -ComputerName $computer -Credential $Cred -ThrottleLimit 16 -ErrorAction SilentlyContinue
Import-PSSession -Session $s -CommandName *-Process -Prefix Remote -AllowClobber
$PCCNTMON = Get-RemoteProcess -name 'PCCNTMON' -ErrorAction SilentlyContinue
If($PCCNTMON -eq $null)
{
Write-Host $($Computer +" Process has already stopped") -BackgroundColor Red
}
Else
{
$PCCNTMON | Stop-Remoteprocess -force -ErrorAction SilentlyContinue
}
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process NTRmv.exe -WorkingDirectory "%programfiles(x86)%\Trend Micro\OfficeScan Client"}
$s | Remove-PSSession
}
Else
{
write-host $($computer + ' is offline')
}
}