cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
julianbr
Engaged Sweeper
Hi! I have some issues when deploying my PowerShell script. It works perfectly when I run it locally on my machine, but when I deploy it, it does not work. All my other PS scripts works, so maybe there is something that I have overlooked? I want to delete some of the printers that the users have, and add some new + setting it as default. I hope someone can help me with this one.

I'm deploying it with the command:
powershell.exe -executionpolicy bypass -file "{PackageShare}\NO.SCR\Add-And-Remove-Printers.ps1"


Here is the PS script:

Get-Printer
add-printer -ConnectionName "\\APP01\SafeQ-Color"
add-printer -ConnectionName "\\APP01\SafeQ-BW"
(New-Object -ComObject WScript.Network).SetDefaultPrinter('\\APP01\SafeQ-BW')
(New-Object -ComObject WScript.Network).RemovePrinterConnection("\\APP01\Safecom_Black")
(New-Object -ComObject WScript.Network).RemovePrinterConnection("\\APP01\Safecom_Color")
Remove-Printer -Name "\\APP01\Safecom_Black"
Remove-Printer -Name "\\APP01\Safecom_Color"
Remove-Printer -Name "\\APP01\osl-03-m"
Remove-Printer -Name "\\APP01\osl-04-m"
Remove-Printer -Name "\\APP01\osl-05-m"
Remove-Printer -Name "\\APP01\osl-06-m"
Remove-Printer -Name "\\APP01\osl-07-m"
New-Item -Path "C:\Temp" -Name "Print-Completed.txt" -ItemType "file" -Value "The command was a success."
Write-Host 'Completed!'


I'm open to suggestions if you know a better way to do this.
4 REPLIES 4
KrisNelson
Champion Sweeper
The problem your going to have is that your script is going to run in the context of the account that is deploying it. Therefor any printers added will not be available to the user anyway.

I would imagine you don't want printers installed locally, which just means your users are going to have to install the printers themselves.

-Kris
julianbr
Engaged Sweeper
Thank you for answering. I have checked the path and everything is correct. The script runs on the user's computers, but the only thing that is working in this line:

New-Item -Path "C:\Temp" -Name "Print-Completed.txt" -ItemType "file" -Value "The command was a success."


I checked the user's temp folder and the file is created, but the printers are not added or removed.

If I run the PS script locally on my machine everything is working as intended. I don't understand what is going on here.

looktall
Engaged Sweeper III
Julian B wrote:
Thank you for answering. I have checked the path and everything is correct. The script runs on the user's computers, but the only thing that is working in this line:

New-Item -Path "C:\Temp" -Name "Print-Completed.txt" -ItemType "file" -Value "The command was a success."


I checked the user's temp folder and the file is created, but the printers are not added or removed.

If I run the PS script locally on my machine everything is working as intended. I don't understand what is going on here.



Sounds like permissions.
What account do you use to run the deployment?
looktall
Engaged Sweeper III
The obvious things to check first would be that the path is correct to the ps1 file and that the deployment runs using an account with the appropriate permissions to perform the tasks.