Hey everyone! I'm working on a PowerShell script to standardize printer names across multiple PCs connected to the same printer with a specific IP. The script also aims to install the HP Universal Driver if it's not already installed. The issue I'm facing is that the Start-Process command isn't working as expected, and the driver isn't installing as it should. Here's a snippet of my script:
```powershell
$printerip = Read-Host "Enter Printer IP Address"
$printername = Read-Host "Enter Uniform Printer Name:"
Get-PrinterDriver
$printerdriver = "HP Universal Printing PS"
$checkdriver = Get-PrinterDriver -Name "HP Universal Printing PS"
if($checkdriver -eq $null) {
Write-Host "Driver not installed, installing driver now"
Start-Process -FilePath "\172.17.9.185companyitSoftware and DriversdriversHP PCL 6Install.exe" -ArgumentList "/s" -NoNewWindow -Wait
}
```
I confirmed the path is correct with Test-Path and I don't see any related processes when I check with Get-Process while the script runs. I would appreciate any help or ideas on why it's not working. Thanks!
3 Answers
Have you tried checking the exit code from the Start-Process command? You can do this by modifying your command to include `-Passthru`, which allows you to retrieve the exit code. It might give you insight on why it’s failing.
Instead of using Start-Process, consider running the command directly and checking `$LASTEXITCODE`. If you run it like this: `& '\172.17.9.185companyitSoftware and DriversdriversHP PCL 6Install.exe' /s`, you might get a clearer result, especially if it fails immediately.
I often run into issues using executables on network paths. A workaround is to copy the EXE to a local path and execute it from there. You could also use `-RedirectStandardOutput` and `-RedirectStandardError` to see what's happening during the installation. If you have access to the driver files, you can install them manually without the EXE.
I’ll give copying the EXE a try! Thanks for the tip!