1

I have a query in SCCM that will take a printer IP address and return all workstations in SCCM that have the printer installed on it. I am wanting to create a powershell script that will take said query and use the workstations that it returns to then list current print jobs in the print queue on the workstation.

I know that you can use Get-CIMInstance -query to query different things in WMI. That works well if I am trying to find out information locally. However if I dump the WQL query into a Here-String and assign it to a variable and then call it with Get-CIMInstance -query it returns an error saying invalid query. The same thing happens when I use Get-WmiObject -Namespace "root\wmi" -Query $WQlquery

So how would I be able to use the WQL query from SCCM in powershell? Here is an example of what I have so far:

$WQLquery = @"
select SMS_R_System.Name from
SMS_R_System inner join
SMS_G_System_PRINTER_DEVICE on
SMS_G_System_PRINTER_DEVICE.ResourceID = 
SMS_R_System.ResourceId where 
SMS_G_System_PRINTER_DEVICE.PortName like "10.10.10.10"
"@

Get-CIMInstance -query $WQLquery

Assuming that worked and returned a list of workstation ids, I would then use Get-Printjob cmdlet to list current jobs in each workstations print queue. I have found a few questions posted here already that have helped me get this far. Any additional help would be appreciated. Go easy on me, still a newb here.

2
  • What is the actual question here? Commented Jan 24, 2017 at 20:43
  • So how would I be able to use the WQL query from SCCM in powershell? Commented Jan 25, 2017 at 13:35

1 Answer 1

2

You need to specify the namespace for the sccm site root\sms\site_SITECODE and the sccm-server if you're running it from a remote computer. Ex:

$WQLquery = @"
select SMS_R_System.Name from
SMS_R_System inner join
SMS_G_System_PRINTER_DEVICE on
SMS_G_System_PRINTER_DEVICE.ResourceID = 
SMS_R_System.ResourceId where 
SMS_G_System_PRINTER_DEVICE.PortName like "10.10.10.10"
"@

Get-WmiObject -Query $WQLquery -ComputerName "SCCMSERVER" -Namespace "root\sms\site_PRI"
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. One more question, in regards to the namespace attribute, where can I find the site code that I need?
It's the primary site for the clients. You can also use central site if you're using that. If you have access to the sccm-server you will know this. It's listed in WMI on the client and server, configuration manager control panel on the client and in the window title for your ConfigMgr Console on the server (+ lots of places inside the console).
Your console says "connecting to <SITECODE> - <SERVERNAME>". In the window title of the console, it says the same.. "Connected to <SITECODE> - <SERVERNAME>. You can also look in adminsitration where the sites are defined, the site-property for any device etc.. It's pretty much everywhere. :-)
ah I see. I found it under Administration>Site Configuration>Sites. I am still somewhat new to SCCM as my role is primarily support. It can be a powerful tool when combined with Powershell and I am hoping I can ease some of my day to day activities. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.