Win32_Printer Put() Throwing a "Generic Failure" Error

We've been trying to deploy a TCP/IP printer to a non-AD-joined machine using PowerShell.

The function we're using is:

Function CreatePrinter {
    $wmi = ([WMIClass]"\\$ComputerName\Root\cimv2:Win32_Printer")
    $Printer = $wmi.CreateInstance()
    $Printer.CreationClassName = "Win32_Printer"
    $Printer.Caption = $PrinterCaption
    $Printer.DriverName = $DriverName
    $Printer.PortName = $PrinterPortName
    $Printer.DeviceID = $PrinterCaption

Open in new window

However, when running Put(), we receive the following error:

Exception calling "Put" with "0" argument(s): "Generic failure "

We've made sure the driver is pointing correctly, the driver is installed, and all of the required parameters are filled in. Interestingly, this works on a local Windows 10 machine using a different printer, but when trying on a different Windows 7 machine using a different printer, it fails.

Any and all help would be greatly appreciated.
Karl MaloneMailmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cliff GaliherCommented:
If your goal is to use powershell, why aren't you using the add-printer cmdlet? WMI via powershell can be clunky and you really have to dig into MSDN to get the API right.
And then there's native GPO printer deployment which works stable and is very convenient... why use powershell?
Karl MaloneMailmanAuthor Commented:
Cliff Galiher, the Add-Printer cmdlet doesn't exist in Windows 7. The goal of the script is to be flexible and executable on any non-AD machine, 7 or 10, that we need to deploy printers on, which is why we've resorted to trying to use WMI.

McKnife, as stated in the original post, the machine is not joined to Active Directory.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Cliff GaliherCommented:
I don't think you'll be able to get where you want then.  Powershell V2 was very limited, even with its WMI interactions.  There is a *reason* that module wasn't backported and why V3 is a minimum to use it.  (even though you aren't trying to use it, you are hitting similar limitations that prevented it from being backported.)

You could write a gnarly script that might eventually work if you have a separate function for each OS, but realistically I'd just maintain two scripts at that point.  There is the "theory" of it being nice to have one script to maintain, but if the function calls are effectively per-OS, you are maintaining two separate blocks of code that just happened to be lumped together.  Or you can keep things simple and use powershell where it makes sense, and use other methods for older OSes on an "as needed' basis.

If you really want to try to get the code to work, unfortunately I have little advice.  I don't recall the win7 WMI specifics anymore (long since purged from personal brain-RAM), and digging through MSDN for an OS I don't regularly support and in extended support is a bit more effort than I have time to do on a volunteer basis. Sorry.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sorry, for missing that detail.

An idea: your deployment, is it to several machines? Why not do it from remote? shows, how someone uses an OS (there: win8.1) that has the add-printer cmdlet to install a printer on server 2008 R2 from remote - I guess it will work the same way against a remote Win7.
Just for me: was my suggestion tried? It looked very promising and easy at the same time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.