How to Successfully Push an MSI to Remote Workstations Using PowerShell?

0
11
Asked By CuriousCat42 On

I've been trying to use PowerShell to install an MSI file on remote workstations directly from my Domain Controller, but I'm running into issues. The installer gets copied to the remote machine, but when it tries to run, I get an error: "InvalidOperation: Start-Process. This command cannot be run due to the error: The network name cannot be found." I've already enabled WinRM on the target, turned off the firewall temporarily for troubleshooting, and gave Domain Admins full control over the target directory. I'm looking for effective ways to resolve this problem and insights from anyone who's knowledgeable in this area.

5 Answers

Answered By PowerShellWhiz On

I took a stab at revising your script based on suggestions from chatGPT. Here's a cleaned-up version:

```powershell
$computers = Get-Content -Path "C:UsersjpaadminDesktopHosts.txt"
$installerPath = "C:Installchrome.msi"
$installerArguments = "/quiet /norestart"
foreach ($computer in $computers) {
Write-Host "Attempting to install software on $computer..."
try {
Invoke-Command -ComputerName $computer -ScriptBlock {
$tempDir = "C:TempSoftwareInstall"
if (-not (Test-Path $tempDir)) {
New-Item -Path $tempDir -ItemType Directory | Out-Null
}
}
Copy-Item -Path $installerPath -Destination "\$computerC$TempSoftwareInstall" -Force
Invoke-Command -ComputerName $computer -ScriptBlock {
$remoteInstallerPath = "C:TempSoftwareInstallchrome.msi"
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$remoteInstallerPath`" $using:installerArguments" -Wait -PassThru
}
Write-Host "Successfully initiated installation on $computer."
} catch {
Write-Host "Failed to install software on $computer. Error: $($_.Exception.Message)" -ForegroundColor Red
} finally {
Invoke-Command -ComputerName $computer -ScriptBlock {
Remove-Item -Path "C:TempSoftwareInstall" -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
```

Answered By TechSavvyTom On

Instead of trying to execute the MSI using the UNC path like \$computerC$, you should run it as if it's local on the remote machine. So, modify the part of your script that calls Start-Process to use the local path, like C:TempSoftwareInstallchrome.msi, instead of the remote UNC path. This change is necessary because when you're in the Invoke-Command context, the remote machine doesn't recognize itself as \$computer, which is why the error occurs. You just need to point it to the correct local path instead!

CodeNinja89 -

This is absolutely the right approach! Using UNC paths from the machine you’re running the command on can lead to a lot of confusion and errors.

Answered By ScriptGuru2023 On

You're calling Start-Process with a UNC path inside the Invoke-Command block, and that's the issue. The remote machine won’t see itself as \$computer. Just switch to the local path of the installer instead, something like C:TempSoftwareInstallchrome.msi, for the installation command.

Answered By DeploymentDude On

If you’re not specific about the remoting part, you might want to check out the PSAppDeploy toolkit. It's packed with handy commands that simplify a lot of common software installation scenarios. We use it all the time in our SCCM setup, and it really saves time!

Answered By SkepticalSysAdmin On

I see you've turned on WinRM and disabled the firewall for troubleshooting—what's that about? And why give full control to Domain Admins over the target directory? It sounds like your approach could use a bit more thought. Have you considered just using 'localhost' instead of $computer? It seems like that variable might not be resolving correctly.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.