/build/static/layout/Breadcrumb_cap_w.png

Add printer powershell through KACE

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?


0 Comments   [ + ] Show comments

Answers (3)

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.
Posted by: WGM_Jeff 12 years ago
4th Degree Black Belt
2

Have you tried this for your script?

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


Comments:
  • Does not crash explorer, but also does not add the printer even though the KACE believes the script deployment was successful. - philologist 12 years ago
  • 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. - WGM_Jeff 12 years ago
  • 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 - WGM_Jeff 12 years ago
  • 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. - philologist 12 years ago
Posted by: pjgeutjens 12 years ago
Red Belt
2

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


Comments:
  • I'll give these a try and let you know. - philologist 12 years ago
  • 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. - philologist 12 years ago
Posted by: philologist 12 years ago
Red Belt
2

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?


Comments:
  • 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. - WGM_Jeff 12 years ago
  • 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. - philologist 12 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ