I am trying to run a SCCM package that is script to uninstall a list of printers from a users machine. Unfortunately I am in a bit of a catch 22 and I have ran into my deadline for completing this. In a bit of a pickle and seeing f anyone can assist me.
If I run the script from a blank *.ps1 I run into the set-execution policy restriction. I have tried just running the *.ps1 and also with the following command line:
powershell.exe -executionpolicy Bypass -nologo -noninteractive -file .\YSoftScript.ps1
If I run the script from PSADT with SCCM 2012 package settings to run with user rights I get credential prompts.
Any way to assist me with this?
This is my code:
$Content = Get-Content -Path “$dirFiles\Printers.txt”
$Printers = [IO.File]::ReadAllText("$dirFiles\Printers.txt")
foreach ($Printers in $Content) {
Get-Printer | select name | Where-Object {$_.Name -like “$Printers”} | Remove-Printer
Write-Output “Removed $Printers”
}