Hi @dfowler37 !
An 0x1
error in Task Scheduler is indicative of a generic failure, but it can represents a permission error like you stated.
Since the Add Network Printer worklet creates a scheduled task with the user’s next login action being the trigger, I’d like to confirm that the device has been logged out, logged back into.
If you are receiving the same error after the login action, the issue could be related to how the Powershell execution policy is configured in your environment. If it is set to Restricted, AllSigned, or RemoteSigned, it could prevent the task from running. In this case, we can try adding the -ExecutionPolicy Bypass
switch within the worklet’s remediation code on line 91:
$action.Arguments = "-windowstyle hidden -ExecutionPolicy Bypass -command `"if(((get-printer).computername -like `'$prntSvr`') -and ((get-printer).name -like `"*$fName*`")){exit 0};if(Test-Connection -ComputerName $prntSvr -BufferSize 16 -Count 1 -Quiet){Add-Printer -ConnectionName `"\\$prntSvr\$prntName`"}"
Have a great day!
I get the error if i log out and back in as well as if i run it manually. I added the bypass and got the same error.
I did notice it is set to run when any ‘local’ user logs in but we use domain users. When i tried to manually run it under my domain user, i got an error that i don’t have permissions to run this task. I tweeked the worklet to use our Domain Users instead and was able to run it. But i get the same error.
Not sure what the issue is. Task Scheduler doesn’t get very specific with its error.
Edit: Disregard. I didn’t realize i was in the Task Manager as admin. I switch to my user and got the error that my account doesn’t have permission to run this task.
I got it working. Line 91 in the worklet is not structured correctly. I fixed the missing terminators and it worked like it should.
Good morning @dfowler37 ,
Nice find, and I’m glad to hear you got this working.
Can you share which terminator you needed to change on line 91? I can get a ticket in for the Worklets team to make the needed changes.
Thanks!
Sure. So the first line is how it is and the second is how i fixed it. Mostly has to do with double quotes and single quotes.
Not working:
"-windowstyle hidden -command `"if(((get-printer).computername -like `'$prntSvr`') -and ((get-printer).name -like `"*$fName*`")){exit 0};if(Test-Connection -ComputerName $prntSvr -BufferSize 16 -Count 1 -Quiet){Add-Printer -ConnectionName `"\\$prntSvr\$prntName`"}"
Working:
-windowstyle hidden -ExecutionPolicy Bypass -command "if(((get-printer).computername -like '$prntsvr') -and ((get-printer).name -like '*$fName*')){exit 0};if(Test-Connection -ComputerName $prntsvr -BufferSize 16 -Count 1 ){Add-Printer -ConnectionName '\\$prntsvr\prntName'}"
Looks like the whole if statement is in double quotes and all the variables are in both single and double quotes. There is a leading double quote that starts the line but it should start before the if, not before the arguments. Also, I put the variables under single quotes within the if statement. Once i ran the worklet, it created the task. I ran the task manually and the printer was added successfully.
I am working on tweeking the script to make it where it will run the task rather than making the user log out and back in.