I have the following powershell script:

Invoke-Expression 'rundll32 printui.dll,PrintUIEntry /in /q /n "\\printserver\newprinter"'
Invoke-Expression 'rundll32 printui.dll,PrintUIEntry /dn /q /n "\\oldserver\oldprinter"'

It runs without any issue invoking it from the local machine.


I have set the KACE to use an online shell script, loaded the powershell script as a dependancy, and use the following command:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file ".\printer.ps1"


If I use the logged in user, I get a failure with "Error 193 while executing script".  If I use all logged in users, I get a success, explorer.exe crashes, and printers no longer work until the system is restarted.  Has anyone successfully used powershell from the KACE to implement a printer transition?

Answer Summary:
Use the printer management vbs scripts that are on the system: http://technet.microsoft.com/en-us/library/cc725868%28v=ws.10%29.aspx Make sure to change the script extension to .bat.
0 Comments   [ + ] Show Comments


Please log in to comment



Have you tried this for your script?

$PrinterPath = "\\Server\PrintShare" 
$net = new-Object -com WScript.Network 

Answered 04/23/2012 by: WGM_Jeff
Fourth Degree Black Belt

  • Does not crash explorer, but also does not add the printer even though the KACE believes the script deployment was successful.
  • I tested it by running it locally today and it worked. I haven't tested it through KACE. I will try it tomorrow and see what happens.
  • I tested it by creating the .ps1 , uploading it as a dependency and then running this in the KACE Script. You have to change the script name at the bottom as a .bat , and run it as someone with rights to add the printer. It does pop up a window on the target machine for a second or so, but it does add the printer

    @echo off

    %windir%\system32\windowspowershell\v1.0\powershell.exe -windowstyle hidden .\printer.ps1
  • Let me know; I've been finding a lot of scripts recently where things work locally, but don't work through the KACE. As mentioned, the rundll method above works without issue on the local machine. I've had similar problems with a powershell script to add a wireless profile, which I have down to one line that runs without issue locally, but the KACE cannot process correctly. The common thread I've seen so far is that the KACE is having difficulty interacting as soon as you get outside the SYSTEM account.
Please log in to comment

you might want to use the printer management vbs scripts that are on the system,

See here: http://technet.microsoft.com/en-us/library/cc725868%28v=ws.10%29.aspx

Answered 04/24/2012 by: pjgeutjens
Red Belt

  • I'll give these a try and let you know.
  • Sadly, this gives the same result. I can run it locally without any issues. When the KACE runs the same command, it returns a successful run for the script, but the printer is not installed.
Please log in to comment

Ok, thank you both for your help. I have a theory as to why I am having so much difficulty.

When I create an online script in the KACE, is the KACE downloading the dependencies and running the script against the machine, or is the KACE downloading the script and the dependencies and running the script on the machine?

I have a feeling what is happening is that since I was not changing the main script extension from the default .sh, I have been trying to run the container script as a bash file. This would normally generate an error from the KACE, but since I happen to use gVim as an editor, gVim is running the container .sh script, and the KACE doesn't care whether gVim returns an error trying to run the dependency, so it returns the script deployment as successful regardless of whether the dependency was ever run.

Does this sound plausible as the tragedy that is occurring here?

Answered 04/24/2012 by: philologist
Red Belt

  • Sounds like it could be the case. I usually get an error if I leave the script name as a .sh file. If I change it to a .bat file it usually runs.
  • This does now work, even with the powershell. In terms of the DOS window showing up, in some other threads here they talk about a way to hide batch scripts. I'll look into it. I know my users get upset when they see a command prompt open and they don't know what it does.
Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja