I'm trying to uninstall MS Office 2007 on all workstations in my Active Directory. For this, I have to launch C:\Transfer2007\setup.exe which is configured by the UninstallConfig.xml file for a silent uninstallation (located in the same directory). PowerShell's Invoke-Command doesn't return any errors and it seems as everything is fine, but the setup.exe never launches on the target workstation.
When I launch the setup.exe manually, I get the 'Open File - Security Warning' where I have to press 'Launch'. In the next step, I get asked for administrator access (UAC). I think these popups are the problem as to why the .exe never launches when trying to run it remotely through PowerShell.
I already tried to include the following in the code:
–ExecutionPolicy Bypass
-Credential parameter with admin rights
UninstallationConfig.xml file:
<Configuration Product="ProPlus">
<Display Level="none" CompletionNotice="no" />
<SettingId="SETUP_REBOOT" Value="AutoAlways" />
</Configuration>
PowerShell code:
Invoke-Command -ScriptBlock {
Set-Location "C:\Transfer2007\";
.\SETUP.exe /uninstall ProPlus /config \UninstallConfig.xml
} -Credential mmb -ComputerName $Computer -AsJob
Try execute this ScriptBlock
$app = Get-WmiObject -Class Win32_Product |
Where-Object {$_.Name -match "Office"}
$app.Uninstall()
OR
Invoke-Command -ComputerName server01 -ScriptBlock {
Start-Process 'C:\Transfer2007\SETUP.exe' -ArgumentList '/uninstall ProPlus /config \UninstallConfig.xml' -Wait
} -Credential (Get-Credential 'localhost\Administrator') -ComputerName $Computer -AsJob
Related
I'm trying to run a command on a VM using Invoke-Command. The command should stop a program that processes jobs after it finishes its current job. It works if I run it in the terminal using RDC.
& 'C:\Program Files\Autodesk\Vault Client 2021\Explorer\JobProcessor.exe' /stop
But if I run it from a different machine using Invoke-Command nothing seems to happen.
$session = New-PSSession -ComputerName 'hostname' -Credential (Get-Credential)
Invoke-Command -Session $session -ScriptBlock {
& 'C:\Program Files\Autodesk\Vault Client 2021\Explorer\JobProcessor.exe' /stop
}
However Process Monitor shows the command come in for both cases, but the program is still running.
I have also tried using Start-Process with the same result, i.e. it works in the terminal on the VM but not using Invoke-Command.
Start-Process -FilePath 'C:\Program Files\Autodesk\Vault Client 2021\Explorer\JobProcessor.exe' -ArgumentList '/stop'
I've been stuck for many days and I've exhausted my googlable knowledge for this problem.
Are you sure that file exists on the remote computer?
For simplicity, I rewrote your command to a known executable that is always there in Windows and returns unique info for any given computer.
C:\> & 'C:\Windows\system32\HOSTNAME.EXE'
server1
C:\> icm {& 'C:\Windows\system32\HOSTNAME.EXE'}
server1
C:\> icm {& 'C:\Windows\system32\HOSTNAME.EXE'} -ComputerName server2
server2
Here's your script with some error handling.
$session = New-PSSession -ComputerName 'hostname' -Credential (Get-Credential)
Invoke-Command -Session $session -ScriptBlock {
$exe = 'C:\Program Files\Autodesk\Vault Client 2021\Explorer\JobProcessor.exe'
$ok = Test-Path $exe
if ($ok) {& $exe /stop} else {
Write-Warning "EXE not present on $($env:COMPUTERNAME)!"
}
}
Learn how to add error handling and you'll be well on your way to solving your problems faster and getting more stuff done.
I am trying to write a Powershell script which will deploy software on a collection of WS2016 servers. I am a local administrator on all these servers. Here's what I have so far:
$Cred = Get-Credential
$Computer = 'myserver.contoso.com'
$SplunkMSI = '\\mylocalbox\C$\Splunk.msi'
$InstallDir = 'C:\Apps\Splunk\'
$sb = {
param($installer, $dir)
Start-Process -FilePath 'c:\windows\system32\msiexec.exe' -ArgumentList "$installer INSTALLDIR=$dir AGREETOLICENSE=Yes /qn /norestart /L*v C:\temp\splunkInstall.log" -Wait -NoNewWindow
}
Write-Host "Deploying Splunk to host $Computer"
Invoke-Command -Computer $Computer -Credential $Cred -ScriptBlock $sb -ArgumentList $SplunkMSI, $InstallDir -ErrorAction Stop
When I run this script, I get prompted for credentials, and then I see the output of the Write-Host, but then... nothing. I have to manually terminate the script.
I logged onto the remote host, but see no evidence that the MSI was executed or failed to execute.
Anyone see a smoking gun?
ya, it looks like it's looking for $installer and $dir in the script block but they're not specified
I am running the below Invoke-WMImethod against remote machines to 7zip up a backup archive. On Win7 it works just fine, on WinXp it dies. I am guessing it dies on the -p$pass in my 7zip options.
$pass = Read-Host "Enter backup password"
$7zip = "cmd /c $backuploc\7za.exe a $backupname.7z -p$pass -mhe $backupfolder"
InVoke-WmiMethod -class Win32_process -name Create -ArgumentList $7zip -ComputerName SVR1 -Credential $cred | Out-Null
Again this is working just fine on the Win7 boxes..why does this fail on XP? and is there a way to get the password option working. (without hard coding password, exclude WinRM also)
Hi When I run this powershell code my powershell just hangs
Set-Content "\\$remote_computer\users\bkoo004\downloads\test\installme.bat" -value 'START "installing" "S:\npp.6.3.3.Installer.exe" /S'
Invoke-Command -ComputerName $remote_computer -Credential $cred -ScriptBlock {Start-Process 'c:\users\bkoo004\downloads\test\installme.bat' -Wait}
But if run this code
Set-Content "\\$remote_computer\users\bkoo004\downloads\test\installme.bat" -value 'START "installing" "C:\users\user\downloads\npp.6.3.3.Installer.exe" /S'
Invoke-Command -ComputerName $remote_computer -Credential $cred -ScriptBlock {Start-Process 'c:\users\bkoo004\downloads\test\installme.bat' -Wait}
I can install fine.. I am thinking that its some UAC or other security that is trying to block my install from a UNC path(drive S). Can anyone please help? Is it because double hop?
The idea here is to uninstall a program silently. Unfortunately the program's msi is custom and executes a batch file during the uninstall process. What I am trying to do is prevent this window from displaying during the powershell uninstall script. I'm using wmi uninstall method because the msi that the program uses doesn't respond to quite or uninstall flags (/q, /x, /uninstall). I have attempted to run it as a background job but the window still appears. The script looks as follows:
start-job -scriptblock `
{(Get-WmiObject -class Win32_Product |? {$_Name -eq "Annoying1"}).uninstall()} `
-Name Uninstall1
$job = get-job -name Uninstall1
wait-job $job
receive-job $job
This will run mostly hidden until the uninstall job gets to the point where the batch file is executed, at which point a cmd window will appear and run. Any ideas of how to run this script without displaying extra windows?
The script is ran with -windowstyle hidden as well.
Be indulgent, I'am not proud of this, but I'am quite sure that if you try to localy run your script using remoting the window will not be seen by the user :
I just try :
$sess = New-PSSession -ComputerName localhost
Invoke-Command -Session $sess -ScriptBlock {calc.exe}
get-process "calc"
In your case try :
$sess = New-PSSession -ComputerName localhost
$job = Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject -class Win32_Product |? {$_Name -eq "Annoying1"}).uninstall()} -asjob -Name Uninstall1
wait-job $job
receive-job $job