PowerShell Remote Installation of exe - Not able to install - powershell

I am trying to install exe on remote machine by using below script, but it didn't succeed. The exe file is on remote machine.
Invoke-Command -ComputerName COMPUTER -ScriptBlock{
Start-Process c:\Windows\Temp\ccsetup.exe -ArgumentList '/silent' -Wait
}
I tried giving different paths but it is not helpful.

Related

Run bat file via PowerShell

I am trying to run a batch file from remote computer but it also doesn't work locally
Invoke-Command -ComputerName $remoteComputer -ScriptBlock {
Start-Process "C:\Users\Administrator\Desktop\version\Installer\Installer.bat" -NoNewWindow -Wait
} -Credential $credentials -ErrorAction Stop
There is no errors but nothing happens
The installer.bat is located under C:\Users\Administrator\Desktop\version\Installer
The batch file contain setup.exe that also located at the same folder.
I am searching for hours the solution
For local I used this:
Start-Process "cmd.exe" "/c C:\Users\Administrator\Desktop\version\Installer\Installer.bat" -NoNewWindow
Seems that its working locally when i am going to the right folder (cd c:..)
and run
Invoke-Expression -Command 'cmd.exe /C C:\Users\Administrator\Desktop\version\Installer\Installer.bat'
So how can i do it remotely (I mean to go to the right path first)

How to Remotely Invoke Applications (.exe file) with PowerShell with remote pc on windows?

I'm trying to execute following command on remote server:
Import.exe. file resides on remote server and this command is completely working on remote server's command line. But when I try to execute it from local system its not showing any error but still not producing any output.
Here is the command :
Start-Process -NoNewWindow -FilePath "C:\\V11\\IMPORT.EXE" -ArgumentList "cutrite1620626276329","/AUTO","/OVERWRITE"
I have connected to remote pc using ssh command.
Note : Both pc, mine and remote pc, are windows.
Start-Process command will execute process on localhost. (More on that here:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-5.1)
What you want to do is invoke this command in PSRemoting session like:
Invoke-Command -ComputerName "COMPUTERNAME" -ScriptBlock {
#This command will be executed on machine COMPUTERNAME
Start-Process -NoNewWindow -FilePath "C:\\V11\\IMPORT.EXE" -ArgumentList "cutrite1620626276329","/AUTO","/OVERWRITE"
};
There are several ways to access psremoting (you can read it here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote?view=powershell-5.1)

How to run a .bat file in a VM from Powershell

I am trying to parallelize an operation by running .bat files in several remote VMs simultaneously using a Powershell script from a local VM. I can successfully run the .bat file in the local VM by using the following:
Start-Process cmd.exe -ArgumentList $batOptimization_path, $vmNumberParam, $rInstanceParam, $optDataParam, $dataSetParam
The first param in -ArgumentList is the path where the .bat file is located, the rest are command line parameters for the .bat file. To try to run the .bat file on a VM, I am using the following:
$psSession = New-PSSession -ComputerName $script:FsvRConfig.VmList[$i].IpAddress
Invoke-Command -ArgumentList $batOptimization_path, $vmNumberParam, $rInstanceParam, $optDataParam, $dataSetParam `
-Session $psSession `
-ScriptBlock {Start-Job -ScriptBlock { Start-Process cmd.exe -ArgumentList $args[0], $args[1], $args[2], $args[3] -AsJob}} `
-ErrorAction SilentlyContinue
This does not run the .bat files properly. The jobs start and then fail, so obviously this is not the way to launch the jobs. Any advice on getting the .bat files to launch in the remote VMs the way it does in the local VM would be greatly appreciated!

Powershell/batch uninstall script works locally but not when using invoke-command

I have a script that installs an .exe with some arguments remotely to a list of servers that works fine. When I try to do almost the exact same thing but run the uninstall.exe that gets installed to C:\Program Files (x86)\ it won't work.
When I run the scripts on the server locally, it kicks off the uninstall. When I try to run the exact same script or command using the powershell invoke-command it won't work.
$serverlist = Get-Content -Path C:\NagiosInstall\test.txt
ForEach ($server in $serverlist) {
New-Item -Path "\\$server\C$\" -Name "NagiosInstall" -Force -ItemType "directory"
Copy C:\NagiosInstall\ncpa-2.1.6.exe \\$server\C$\NagiosInstall\ncpa-2.1.6.exe
Copy C:\NagiosInstall\install.bat \\$server\C$\NagiosInstall\install.bat
invoke-command -ComputerName $server -ScriptBlock {C:\NagiosInstall\install.bat}
Start-Sleep -s 15
invoke-Command -ComputerName $server -ScriptBlock {Remove-Item -LiteralPath "C:\NagiosInstall" -Force -Recurse}
}
The install .bat is just a simple command to silently install that ncpa-2.1.6.exe.
Above is my install script, that part all works fine.
invoke-command -ComputerName $server -ScriptBlock {Start-Process -FilePath "C:\Program Files (x86)\Nagios\NCPA\uninstall.exe" -ArgumentList "/S"}
Running the above command, nothing happens. No errors, nothing.
& "C:\Program Files (x86)\Nagios\NCPA\uninstall.exe" -ArgumentList "/S"
But running the above command in powershell that's running as admin locally on the server and it works just fine.
I've also tried the same approach to create and copy and run a batch file, very similar to the above "install" code. Same thing... nothing happens but if you run the batch locally on the server, it works just fine. I can post this code if anyone is interested.
I'm guessing it has to do with the invoke-command or the fact that it's in C:\Program Files (x86) which might make the syntax different, but I've tried many things and I'm out of ideas besides making an account and posting here.
The issue is that Invoke-Command runs non-interactively, and therefore cannot run as Administrator and respond to a UAC prompt.
The only workaround is to connect to the computer via a PSSession with credentials, and execute it that way:
$Cred = Get-Credential
$Session = New-PSSession -ComputerName $server -Credential $Cred
Invoke-Command -Session $Session -ScriptBlock {Start-Process -FilePath "C:\Program Files (x86)\Nagios\NCPA\uninstall.exe" -ArgumentList "/S"}
$Session | Exit-PSSession
Edit:
The reason that the installer works is that the UAC prompt for Windows Installs is different than anything else in Windows see: How to Silence the UAC Prompt for Per-Machine MSI Packages for Non-Admins or Using Windows Installer with UAC.
Essentially, Windows Installer (already running as admin and UAC approved), is what runs the install on your behalf, and it is Windows Installer and installer settings that determines if you need to see a UAC prompt or not. Hence, this is why the install works. Windows Installer determined that you did not need to see the UAC prompt, and the install proceeds.
Uninstalling is different. Since you are running uninstall.exe, the executable needs admin access and Windows will do UAC before the uninstall.exe even runs.

Unable to execute EXE remotely using Powershell

There is an exe file on backup server “Backupsrv” C:\Program files\Veritas\NetBackup\bin\admincmd\bpdbjobs.exe.
When I run this exe on “Backupsrv” using PowerShell it is giving some output on console
& "C:\Program Files\Veritas\netbackup\bin\admincmd\bpdbjobs.exe" -all_columns
Now I tried to run this exe from an application server remotely using Invoke-Command as below.
$result = Invoke-Command -ComputerName "backupsrv" -Credential $cred -ErrorAction Stop -ScriptBlock {
& "C:\Program Files\Veritas\netbackup\bin\admincmd\bpdbjobs.exe" -all_columns
}
No result When executed remotely.
The exe is being executed but not giving any result.