I am having issue getting runAs =Current user to work. The project I am stuck with should be an easy one but a week later I still don’t have this issue resolved. The server team has moved our print servers to the cloud. so I wrote a small powershell script to run and detect what printer that is installed and move that printer to the new print server. This works with admin and non-admin domain accounts manually. I have 22,000 endpoints across America to change. I need the printers to be changed as the current logged on domain user that does not have admin rights. I have the printers checking if they exist on the new server against an array. Again this works manually. I think big fix is not completely running the script as the current logged on user rather as the System Account. The task will run but the switching of the print servers is ignored. I hope that explanation is clear. If not ask away I will try to answer your questions. Thank you for your help in advance.
Oh and one caveat. if the user does have admin rights this task works flawlessly. go figure about 100 endpoint have admin rights. 21,900 to go.
Here is my script:
parameter “baseFolder” = “__Download/”
parameter “mainSWDLogFolder” = "{parent folder of client folder of current site}/__Global/SWDDeployData"
folder create "{parameter “mainSWDLogFolder”}"
parameter “logFile” = “SWD_DeploymentResults.log”
delete powershell.ps1
delete {parameter “baseFolder”}powershell.ps1
delete __createfile
parameter “logFolder” = “{parameter “mainSWDLogFolder”}”
createfile until end
$AW2PRINTSVRP04 = @(“csc101-pcl6”, “csc101-PC6-old”, “cac101-xc”, “csc104-pcl6”, “csc106-pcl6”, “csc106-xc”, “csc107-pcl6”, “csc112-pcl6”, “csc112-xc”, “csc113_2-pcl6”, “csc113_2-xc”, “csc113_2-XColor”, “csc113-pcl6”, “csc113-xc”, “csc115-pcl6”, “csc115-pcl6”, “csc115-xc”, “csc117-pcl6”, “csc117-xc”, “csc120-pcl6”, “cac120-xc”, “csc123-pcl6”, “csc123-xc”, “csc201-pcl6”, “csc201-xc”, “csc202-pcl6”, “csc202-xc”, “csc204-xc”, “csc207-pcl6”, “csc207-xc”, “csc209-pcl6”, “csc209-xc”, “csc210-pcl6”, “csc212-pcl6”, “csc214-pcl6”, “csc216_7-pcl6”, “csc216-pcl6”, “csc218-pcl6”, “csc221-pcl6”, “csc225-pcl6”, “csc226-xc”, “csc229-xm”, “CSC-Lobby”, “ic116-pcl6”, “ic116-xc”, “ic142-xm”, “ic211-pcl6”, “ic211-xc”, “ic222-pcl6”, “ic222-xc”, “ic257-pcl6”, “ic257-xc”, “ic261-XM PostScript”, “ic262-pcl6”, “ic262-xc”, “ic-lobby”)
$AW2PRINTSVRP03 = @(“csc106_1”, “csc106_p”, “csc107-1”, “csc107-p”, “csc112-1”, “csc112-p”, “csc113_1-1”, “csc113_1-p”, “csc113_2-1”, “csc213_2-p”, “csc120-1”, “csc120-p”, “csc202-1”, “csc202-p”, “csc209-1”, “csc209-p”, “csc214-p”, “csc216-1”, “csc216-1”, “csc216-p”, “csc226-1”, “csclobby-L”, “cscLobby-P”, “DesignJet T7200”, “ic116-1”, “ic116-p”, “phoenix-1”, “phoenix-p”)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$userSid =([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$printers = Get-ChildItem -Path HKU:$userSid\Printers\Connections\ -name
Foreach ($Entry in $printers) {{
$printerStr = $Entry.Split(",")
$server = $printerStr[2]
$printerName = $printerStr[3]
Write-Host "printer is $printerName on server $server."
if ($server -eq “Printserver4”) {{
if ($printerName -in $AW2PRINTSVRP04) {{
write-host "Printer $printerName Exists in array"
Remove-Printer -Name “\$SERVER$printerName”
$server = "AW2PRINTSVRP04"
Add-Printer -ConnectionName “\$server$printerName”
}
else {{
if ($printerName -in $AW2PRINTSVRP03) {{
write-host "Printer $printerName Exists in array"
Remove-Printer -Name “\$SERVER$printerName”
$server = "AW2PRINTSVRP03"
Add-Printer -ConnectionName “\$server$printerName”
}
}
}
}
Remove-PSDrive -Name HKU
end
move __createfile {parameter “baseFolder”}powershell.ps1
override wait
completion=none
RunAs=currentuser
wait powershell -ExecutionPolicy Bypass -File "{parameter “baseFolder”}powershell.ps1"
pause while {exists running application “powershell.exe”}