WMI, Powershell, and Various Scripts for SCCM Task Sequences

I’ve been experimenting with Microsoft System Center Configuration Manager (SCCM) at work a lot lately.  In the course of my experimentation for OS Deployment (OSD), I’ve stumbled onto a number of helpful Powershell, WMI, and batch scripts that I’ve found quite useful.  These references can be particularly useful if you decide to go without the Microsoft Deployment Toolkit (MDT) and stick with a “strictly” SCCM-based task sequence.

NOTE:  Unfortunately, I didn’t keep a link to all the appropriate original owners of the following content, but I was hoping to summarize them all here for quick reference.  Hopefully it can provide you some assistance as well!

Helpful DISM commands:

The following commands can be useful for offline role installation prior to the “Setup Windows and Configuration Manager” step.  (Note:  %OSDisk% refers to the Variable where my WIM file is copied locally):

  • Install a Role:
    • cmd /c Dism.exe /image:%OSDisk%\ /Enable-Feature /FeatureName:Microsoft-Hyper-V /LogPath:%_SMSTSLogPath%\Hyper-V.log
  • Install Required Prerequisite Features In A Feature Pack:
    • cmd /c Dism.exe /image:%OSDisk%\ /Enable-Feature /FeatureName:Microsoft-Hyper-V-Management-Clients /FeatureName:Microsoft-Hyper-V-Management-PowerShell /all /LogPath:%_SMSTSLogPath%\Hyper-V-RSAT.log

Helpful WMI Queries:

The following queries can be useful as task conditions:

  • FINDING HARDWARE by PNP “Name”:
    • Select * from win32_PNPEntity where Caption like “Intel(R) Gigabit%”
    • Select * from win32_PNPEntity where caption like “Qlogic Fibre Channel%”
  • HYPER-V VIRTUAL MACHINE:
    • YES:   select * from Win32_ComputerSystem where model = “Virtual Machine”
    • NO:   select * from Win32_ComputerSystem where model <> “Virtual Machine”
  • HARDWARE MODELS:
    • DELL:   Select * FROM Win32_ComputerSystem where Manufacturer=”Dell Inc.”
      • Select * FROM Win32_ComputerSystem where Model=”PowerEdge R620″
      • Select * FROM Win32_ComputerSystem where Model=”PowerEdge T620″
    • HP:     Select * FROM Win32_ComputerSystem where Manufacturer=”HP”
      • Select * FROM Win32_ComputerSystem where Model=”ProLiant BL460c G7″
      • Select * FROM Win32_ComputerSystem where Model=”ProLiant DL380 G7″
      • Select * FROM Win32_ComputerSystem where Model=”ProLiant DL380p Gen8″
      • Select * FROM Win32_ComputerSystem where Model=”ProLiant BL460c Gen8″

NOTE:  I find it useful to ensure Powershell support is added to my WinPE Boot Image.  This way I can use Powershell to easily explore the WMI classes present on the machine and use that to build task conditions.

SCCM Client Schedules:

If you need to kick off an SCCM Client schedule manually, the following Schedule IDs should assist.  I’ve included a Powershell command which you can run as a “Run Command Line” task in order to trigger the schedule.

  • HW Inventory – {00000000-0000-0000-0000-000000000001}
  • SW Inventory – {00000000-0000-0000-0000-000000000002}
  • Discovery Data Record – {00000000-0000-0000-0000-000000000003}
  • Machine Policy Retrieval & Evaluation – {00000000-0000-0000-0000-000000000021}
  • File Collection – {00000000-0000-0000-0000-000000000010}
  • SW Metering Usage Report – {00000000-0000-0000-0000-000000000022}
  • Windows Installer Source List – {00000000-0000-0000-0000-000000000032}
  • Software Updates Scan – {00000000-0000-0000-0000-000000000113}
  • Software Updates Store – {00000000-0000-0000-0000-000000000114}
  • Software Updates Deployment – {00000000-0000-0000-0000-000000000108}

Helpful Powershell Commands:

Some quick and dirty commands to help you run “one-liners” in the task sequence:

  •  powershell.exe -noprofile -Command “&{code goes here}”
    • Example:  powershell.exe -noprofile -Command “&{([wmiclass]’root\ccm:SMS_Client’).TriggerSchedule(‘{00000000-0000-0000-0000-000000000010}’)}”
    • Quick and easy if you’re not concerned about error-handling for your Powershell Code… it always returns a success (0).
  • powershell.exe -noprofile -Command {$global:errorActionPreference=’Stop’;code goes here;exit $LASTEXITCODE}
    • Example:  powershell.exe -noprofile -Command {$global:errorActionPreference=’Stop’;(Get-WmiObject -class Win32_TSGeneralSetting -Namespace root\cimv2\terminalservices -Filter “TerminalName=’RDP-tcp'”).SetUserAuthenticationRequired(1);exit $LASTEXITCODE}
    • Slightly more intense.  As you can see the code block contains THREE lines of code (separated by semi-colons).
    • This method of command line allows the command interpreter to pass back failure codes to SCCM.

Hope you find this a helpful reference.  I plan to grow this as I find more good nuggets!

About Robert

An IT nerd with 10+ years of experience in almost *anything* windows (server and desktop), Citrix, Exchange, Google Apps, and WordPress. I like to dabble in just about anything IT related, and read blogs and tech books like crazy!

Find Robert on , and Twitter.

Speak Your Mind

*