Querying information by using WMI and CIM
Exercise 1: Querying information by using WMI
Task 1: Query IP addresses
- On LON-CL1, select Start, and then enter powersh.
- In the results list, right-click Windows PowerShell or activate its context menu, and then select Run as administrator.
- 
    To find a repository class that lists the IP addresses being used by a computer, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Namespace root\cimv2 -List | Where Name -like '*configuration*' | Sort NameNotice the Win32_NetworkAdapterConfigurationclass.
- 
    To retrieve all instances of the class depicting static IP addresses, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where DHCPEnabled -eq $False | Select IPAddressRemember that you can run the first command and pipe its output to Get-Member to review the properties that are available. 
Task 2: Query operating system version information
- 
    To find a repository class that lists operating system information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Namespace root\cimv2 -List | Where Name -like '*operating*' | Sort NameNotice the Win32_OperatingSystemclass.
- 
    To display a list of properties for the class, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_OperatingSystem | Get-Member
- 
    Notice the Version, ServicePackMajorVersion, and BuildNumber properties. 
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_OperatingSystem | Select Version,ServicePackMajorVersion,BuildNumber
Task 3: Query computer system hardware information
- 
    To find a repository class that displays computer system information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Namespace root\cimv2 -List | Where Name -like '*system*' | Sort NameNotice the Win32_ComputerSystemclass.
- 
    To display a list of instance properties and values, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_ComputerSystem | Format-List -Property *Remember that Get-Memberdoesn’t display property values, butFormat-Listcan.
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_ComputerSystem | Select Manufacturer,Model,@{n='RAM';e={$PSItem.TotalPhysicalMemory}}
Task 4: Query service information
- 
    To find a repository class that contains information about services, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Namespace root\cimv2 -List | Where Name –like '*service*' | Sort NameNotice the Win32_Serviceclass.
- 
    To display a list of instance properties and values, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_Service | FL *
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and press the Enter key: Get-WmiObject –Class Win32_Service –Filter "Name LIKE 'S%'" | Select Name,State,StartName
- 
    Leave the Windows PowerShell console open for the next exercise. 
Exercise 2: Querying information by using CIM
Task 1: Query user accounts
- 
    To find a repository class that lists user accounts, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimClass -ClassName *user*Notice the Win32_UserAccountclass.
- 
    To display a list of class properties, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimInstance -Class Win32_UserAccount | Get-Member
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimInstance -Class Win32_UserAccount | Format-Table -Property Caption,Domain,SID,FullName,NameNotice the returned list of all domain and local accounts. 
Task 2: Query BIOS information
- 
    To find a repository class that contains BIOS information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimClass -ClassName *bios*Notice the Win32_BIOSclass.
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimInstance -Class Win32_BIOS
Task 3: Query network adapter configuration information
- 
    To display a list of all the local Win32_NetworkAdapterConfigurationinstances, enter the following command in the Windows PowerShell console, and then press the Enter key:Get-CimInstance -Classname Win32_NetworkAdapterConfiguration
- 
    To display a list of all the Win32_NetworkAdapterConfigurationinstances that exist on LON-DC1, enter the following command in the Windows PowerShell console, and then press the Enter key:Get-CimInstance -Classname Win32_NetworkAdapterConfiguration -ComputerName LON-DC1
Task 4: Query user group information
- 
    To find a repository class that lists user groups, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimClass -ClassName *group*Notice the Win32_Groupclass.
- 
    To display the specified information, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-CimInstance -ClassName Win32_Group -ComputerName LON-DC1
- 
    Leave the Windows PowerShell console open for the next exercise. 
Exercise 3: Invoking methods
Task 1: Invoke a CIM method
- 
    To restart LON-DC1, enter the following command in the Windows PowerShell console, and then press the Enter key: Invoke-CimMethod -ClassName Win32_OperatingSystem -ComputerName LON-DC1 -MethodName RebootNotice the response that includes ReturnValue=0 and PSComputerName=LON-DC1. 
- Switch to the LON-DC1 virtual machine and observe it restarting.
- When the restart is complete, switch back to the LON-CL1 virtual machine.
Task 2: Invoke a WMI method
- 
    To review properties of the WinRM service, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-Service WinRM | FL *Note that the StartType is Manual. 
- 
    To change the start mode of the specified service, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-WmiObject -Class Win32_Service -Filter "Name='WinRM'" | Invoke-WmiMethod -Name ChangeStartMode -Argument 'Automatic'
- 
    To verify that the StartType of the WinRM service has changed, enter the following command in the Windows PowerShell console, and then press the Enter key: Get-Service WinRM | FL *Note that the StartType is Automatic.