Bird
Raised Fist0
PowerShellscripting~20 mins

CIM/WMI cmdlets in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
CIM/WMI Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Get-CimInstance for Win32_OperatingSystem
What is the output type of the following PowerShell command?
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Caption, Version
PowerShell
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Caption, Version
AA list of all running processes with their IDs
BAn object with properties Caption and Version showing OS name and version
CA string containing the full OS description
DAn error indicating the class Win32_OperatingSystem does not exist
Attempts:
2 left
💡 Hint
Think about what Win32_OperatingSystem class represents in WMI.
📝 Syntax
intermediate
2:00remaining
Correct syntax to query CIM instances remotely
Which option shows the correct syntax to get the list of services from a remote computer named 'Server01' using CIM cmdlets?
AGet-CimInstance -ClassName Win32_Service -ComputerName Server01
BGet-CimInstance -ClassName Win32_Service -Computer Server01
CGet-CimInstance -ClassName Win32_Service -RemoteName Server01
DGet-CimInstance -ClassName Win32_Service -Host Server01
Attempts:
2 left
💡 Hint
The parameter to specify a remote computer is -ComputerName.
🔧 Debug
advanced
2:00remaining
Identify the error in this CIM query
What error will this command produce?
Get-CimInstance -ClassName Win32_Process -Filter "Name = 'notepad.exe'"
PowerShell
Get-CimInstance -ClassName Win32_Process -Filter "Name = 'notepad.exe'"
AReturns empty result because no notepad.exe process is running
BSyntaxError due to incorrect filter string quotes
CNo error; returns all notepad.exe processes
DRuntime error: Invalid filter property 'Name'
Attempts:
2 left
💡 Hint
Check the filter syntax and property name carefully.
🚀 Application
advanced
2:00remaining
Using CIM cmdlets to restart a service
Which command correctly restarts the 'Spooler' service on the local computer using CIM cmdlets?
A$svc = Get-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'"; Invoke-CimMethod -InputObject $svc -MethodName StopService; Invoke-CimMethod -InputObject $svc -MethodName StartService
BInvoke-CimMethod -ClassName Win32_Service -MethodName StopService -Arguments @{Name='Spooler'}; Invoke-CimMethod -ClassName Win32_Service -MethodName StartService -Arguments @{Name='Spooler'}
CRestart-Service -Name Spooler
DGet-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'" | Restart-CimService
Attempts:
2 left
💡 Hint
You need to get the service instance first, then invoke methods on it.
🧠 Conceptual
expert
2:00remaining
Difference between Get-CimInstance and Get-WmiObject
Which statement best describes the difference between Get-CimInstance and Get-WmiObject cmdlets?
AGet-CimInstance only works locally; Get-WmiObject works remotely
BGet-CimInstance requires admin rights; Get-WmiObject does not
CGet-CimInstance returns raw XML; Get-WmiObject returns objects
DGet-CimInstance uses WS-Management protocol and is more efficient; Get-WmiObject uses DCOM and is deprecated
Attempts:
2 left
💡 Hint
Think about the communication protocols used by each cmdlet.

Practice

(1/5)
1. What does the PowerShell cmdlet Get-CimInstance do?
easy
A. Starts a new PowerShell session.
B. Retrieves management information from local or remote computers using CIM.
C. Deletes files from the system.
D. Installs software packages.

Solution

  1. Step 1: Understand the purpose of Get-CimInstance

    Get-CimInstance is used to get management data from computers, like hardware or software info.
  2. Step 2: Compare options with cmdlet purpose

    Only Retrieves management information from local or remote computers using CIM. describes retrieving management info, matching the cmdlet's function.
  3. Final Answer:

    Retrieves management information from local or remote computers using CIM. -> Option B
  4. Quick Check:

    Get-CimInstance = Retrieves info [OK]
Hint: Get-CimInstance fetches system info, not file or session tasks [OK]
Common Mistakes:
  • Confusing Get-CimInstance with file or session commands
  • Thinking it installs software
  • Assuming it deletes files
2. Which of the following is the correct syntax to get the list of running processes using CIM cmdlets?
easy
A. Get-CimInstance -ClassName Win32_Process
B. Get-CimInstance Win32_Process
C. Get-WmiObject -Class Win32_Process
D. Get-Process -ClassName Win32_Process

Solution

  1. Step 1: Identify correct syntax for Get-CimInstance

    The correct parameter to specify the class is -ClassName, so Get-CimInstance -ClassName Win32_Process is valid.
  2. Step 2: Check other options for syntax errors

    Get-CimInstance Win32_Process misses the parameter name, Get-WmiObject -Class Win32_Process uses Get-WmiObject (older cmdlet), and Get-Process -ClassName Win32_Process uses Get-Process incorrectly with a class parameter.
  3. Final Answer:

    Get-CimInstance -ClassName Win32_Process -> Option A
  4. Quick Check:

    Correct syntax uses -ClassName parameter [OK]
Hint: Use -ClassName to specify CIM class in Get-CimInstance [OK]
Common Mistakes:
  • Omitting -ClassName parameter
  • Mixing Get-CimInstance with Get-WmiObject syntax
  • Using Get-Process with CIM class names
3. What will be the output of this command?
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Caption
medium
A. A list of running processes.
B. The computer's network adapter details.
C. An error about invalid property.
D. The name of the operating system installed on the computer.

Solution

  1. Step 1: Understand the CIM class and property

    The class Win32_OperatingSystem contains OS info; the property Caption holds the OS name.
  2. Step 2: Analyze the command output

    Selecting Caption will output the OS name, not processes or network info, and no error occurs.
  3. Final Answer:

    The name of the operating system installed on the computer. -> Option D
  4. Quick Check:

    Win32_OperatingSystem Caption = OS name [OK]
Hint: Win32_OperatingSystem class holds OS info; Caption is OS name [OK]
Common Mistakes:
  • Confusing OS info with process or network info
  • Expecting full object instead of selected property
  • Assuming property Caption does not exist
4. You run this command but get an error:
Get-CimInstance -Class Win32_Processor

What is the likely cause?
medium
A. The parameter name should be -ClassName, not -Class.
B. Win32_Processor is not a valid CIM class.
C. Get-CimInstance cannot query processor info.
D. You need administrator rights to run this command.

Solution

  1. Step 1: Check the parameter name used

    The correct parameter for specifying the class in Get-CimInstance is -ClassName, not -Class.
  2. Step 2: Verify class validity and permissions

    Win32_Processor is a valid class and Get-CimInstance can query it; admin rights are usually not required for this query.
  3. Final Answer:

    The parameter name should be -ClassName, not -Class. -> Option A
  4. Quick Check:

    Use -ClassName parameter with Get-CimInstance [OK]
Hint: Use -ClassName, not -Class, with Get-CimInstance [OK]
Common Mistakes:
  • Using -Class instead of -ClassName
  • Assuming class is invalid
  • Thinking admin rights are needed
5. You want to list all services that are currently running on a remote computer named 'Server01' using CIM cmdlets. Which command is correct?
hard
A. Get-CimInstance -ClassName Win32_Service -ComputerName Server01 | Where-Object { $_.Status -eq 'Running' }
B. Get-WmiObject -Class Win32_Service -ComputerName Server01 | Where-Object { $_.Status -eq 'Running' }
C. Get-CimInstance -ClassName Win32_Service -ComputerName Server01 | Where-Object { $_.State -eq 'Running' }
D. Get-CimInstance -ClassName Win32_Service -ComputerName Server01 | Where-Object { $_.State -eq 'Stopped' }

Solution

  1. Step 1: Identify the correct property for running services

    The property State with value 'Running' correctly filters running services in Win32_Service.
  2. Step 2: Choose the correct cmdlet and filter

    Using Get-CimInstance with -ComputerName is modern and correct. Filtering with Where-Object { $_.State -eq 'Running' } matches running services.
  3. Final Answer:

    Get-CimInstance -ClassName Win32_Service -ComputerName Server01 | Where-Object { $_.State -eq 'Running' } -> Option C
  4. Quick Check:

    Filter by State='Running' with Get-CimInstance [OK]
Hint: Filter services by State='Running' using Get-CimInstance [OK]
Common Mistakes:
  • Using Status instead of State property
  • Filtering for 'Stopped' instead of 'Running'
  • Mixing Get-WmiObject with CIM cmdlets