0% found this document useful (0 votes)
9 views13 pages

WMI PowerShell Lab for System Admins

The document provides lab instructions for using Windows Management Instrumentation (WMI) in Windows PowerShell, detailing exercises for building a computer inventory, discovering WMI classes, generating logical disk reports, and listing local users and groups. Each exercise includes specific tasks to perform, such as retrieving operating system and BIOS information, filtering logical disks, and generating reports for audit purposes. The lab is designed for systems administrators to manage and monitor domain computers effectively.

Uploaded by

shrikantnpar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

WMI PowerShell Lab for System Admins

The document provides lab instructions for using Windows Management Instrumentation (WMI) in Windows PowerShell, detailing exercises for building a computer inventory, discovering WMI classes, generating logical disk reports, and listing local users and groups. Each exercise includes specific tasks to perform, such as retrieving operating system and BIOS information, filtering logical disks, and generating reports for audit purposes. The lab is designed for systems administrators to manage and monitor domain computers effectively.

Uploaded by

shrikantnpar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Instructions: Windows® Management

Instrumentation
Module 4

Contents:
Lab: Using Windows Management Instrumentation in Windows PowerShell
Exercise 1: Building Computer Inventory
Exercise 2: Discovering WMI Classes and Namespaces
Exercise 3: Generating a Logical Disk Report for All Computers
Exercise 4: Listing Local Users and Groups
Lab: Using Windows Management
Instrumentation in Windows PowerShell
Estimated time: 45 minutes
You work as a systems administrator, and you need to perform certain tasks against the
computers, users, and groups that you manage. You need to check inventory of your computers,
including the operating system versions, service pack versions, and asset tags. Your organization
uses the BIOS serial number as an asset tag tracking system. You need to monitor logical drive
space on multiple remote computers. You also need to generate reports showing local users and
groups on those machines for audit purposes.

Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the lab,
you must:
1. Start the AD, Windows7 virtual machines, and then log on by using the following credentials:
• Username: NEWHORIZONS\administrator
• Password: Passw0rd
2. Disable the Windows Firewall on AD and Windows7
4. On WINDOWS7, open the Windows PowerShell console. All PowerShell commands will be
run within the Windows PowerShell console.
5. On virtual machine WINDOWS7, create a text file containing the names of all computers in
the domain, one on each line, and save it as C:\users\administrator\documents\[Link].

You can either do this in the PowerShell command line if you are able or manually. Its contents
should look as follows:
• AD .[Link]
• [Link]

Exercise 1: Building Computer Inventory


Scenario
You work as a system administrator. Periodically you need to inventory your domain computers.
The inventory information you require includes the operating system version, the service pack
version, and the asset tag. Your organization uses the BIOS serial number as the asset tag for all
computer systems.

The main tasks for this exercise are carried out on WINDOWS7and are as follows:
1. Retrieve the operating system information for the local computer.
2. Extract specific version information from the operating system object.
3. Retrieve operating system version numbers from the local computer “remotely”.
4. Retrieve operating system version numbers from multiple computers in one command.
5. Export operating system version numbers (both the operating system version and the service
pack version) for multiple computers to a .csv file.
6. Retrieve BIOS serial numbers from multiple computers.
7. Create a custom object for each computer containing all inventory information.
8. Export the results of the last command to a file.

� Task 1: Retrieve the operating system information


1. Get the operating system information from the local computer using
Get-WmiObject with the Win32_OperatingSystem class.
2. Show all properties of the Win32_OperatingSystem object you just retrieved.

� Task 2: Extract version information from the operating system object


1. Show all properties of the Win32_OperatingSystem object with version in their name.
2. Generate a table showing the __SERVER, Version, ServicePackMajorVersion, and
ServicePackMinorVersion properties of the Win32_OperatingSystem object.

Hint: The __SERVER property starts with two underscore characters.

� Task 3: Retrieve the local operating system information “remotely”


1. Repeat the last command, passing the WINDOWS7computer name to the ComputerName
parameter of the Get-WmiObject cmdlet.
2. Show the help information for the ComputerName parameter of the Get-
WmiObject cmdlet. Note that ComputerName accepts an array of strings.

� Task 4: Retrieve the operating system information for all computers


1. Read the list of domain computer names from the [Link] file in your documents
folder.
2. Modify the last command you ran to retrieve operating system information so that it shows the
information for all computers in the domain.

� Task 5: Export the operating system information for all computers


1. Read the help information for the Select-Object cmdlet.
2. Replace the call to Format-Table in the last Get-WmiObject command pipeline with Select-
Object, maintaining the list of properties that are required.
3. Export the operating system information to a .csv file called [Link].

� Task 6: Retrieve the BIOS information for all computers


• Retrieve the BIOS information for all computers using the Win32_BIOS class.

� Task 7: Create a custom object for each computer containing all inventory information
1. Read the help information and examples for the Select-Object cmdlet so that you understand
what it is used for and how it works.
2. Combine the operating system version information and BIOS serial numbers into one set of
results using Select-Object.

Hint: This is a complex command. You need to execute Get-WmiObject and use Select-Object to create a
custom column. The expression for that custom column is another call to Get-WmiObject. Refer to the
course material for an example of this complex technique.

� Task 8: Export the inventory report


• Export the results of the last command to a .csv file called [Link].

Results: After this exercise, you should have successfully retrieved operating system and BIOS
information from all computers in your domain, built custom objects using Select-Object, and
generated an inventory report in a .csv file.

Exercise 2: Discovering WMI Classes and Namespaces


Scenario
You are retrieving computer information remotely using WMI. You need to be able to discover
classes and namespaces on a remote computer so that you can get the data you need.

The main tasks for this exercise are carried out on AD and are as follows:
1. View WMI classes in the default namespace on AD .
2. Find WMI classes using wildcards on AD .
3. Enumerate the list of top-level WMI namespaces on the AD computer.

� Task 1: View WMI classes in the default namespace


1. On AD , read help information for the List parameter in the
Get-WmiObject cmdlet.
2. Get a list of all WMI classes in the default namespace on the AD computer.

� Task 2: Find WMI classes using wildcards


1. Find all WMI classes in the default namespace on AD that contain Printer in their class name.
2. Find all WMI classes in all namespaces on AD that contain Printer in their class name.

� Task 3: Enumerate top-level WMI namespaces


1. Enumerate the top-level WMI namespaces by retrieving WMI objects of class
__NAMESPACE in the root namespace on AD .

Hint: The __NAMESPACE class name begins with two underscore characters.

2. Generate a list of only the top-level WMI namespace names by using Get-
WmiObject with Select-Object.

Hint: Sometimes, a property is a collection of other objects. Select-Object can expand that property into a
list of those objects by using the –ExpandProperty parameter. For example, -ExpandProperty Name
expands the Name property

Results: After this exercise, you should be able to find WMI classes in a specific namespace,
find WMI classes using a wildcard search, and find WMI namespaces on local or remote
computers.

Exercise 3: Generating a Logical Disk Report for All Computers


Scenario
To monitor disk-space usage for computers in your organization, you want to use PowerShell to
retrieve and process WMI information.

The main tasks for this exercise are carried out on WINDOWS7and are as follows:
1. Learn how to discover the WMI class used to retrieve logical disk information.
2. Retrieve logical disk information from the local machine.
3. Apply a server-side filter to filter the logical disks to include only hard disks and gather disk
information for all computers in your domain.
4. Add a calculated value to your report showing percent-free information for hard disks for all
computers in your domain.
5. Learn how to discover information related to WMI classes.

� Task 1: Discover the WMI class used to retrieve logical disk information
• Find all WMI classes in the default namespace on the local machine that contain LogicalDisk
in the class name.

Hint: If you examine the help for Get-WmiObject, you see that the -class parameter is positional and is in
position 2. That means you do not have to type the –class parameter name; you can simply provide a
value, if you place it in the correct position.

� Task 2: Retrieve logical disk information from the local machine


• Get all logical disk drives for the local machine using the Get-WmiObject cmdlet.

� Task 3: Retrieve logical disk information for hard disks in all computers in your domain
1. Read help information for the Filter parameter of the Get-WmiObject cmdlet.
2. Read the list of computer names in your domain from the [Link] file in your
documents folder.
3. Get all hard disks for all computers in your domain using the Get-WmiObject cmdlet. The
DriveType property value for hard disks is 3. Show the results in a table with the computer
name, device id, and free-space information.

� Task 4: Add a calculated PercentFree value to your report


• Add a calculated parameter to your hard disk table that has the following properties:
• Label: ‘PercentFree’
• Expression: {$_.FreeSpace / $_.Size}

Hint: You have already seen examples of the structure necessary to create a custom or calculated column.
In this task, you are doing the same thing.

Results: After this exercise, you should know how to check logical disk free-space information
using WMI, how to add calculated properties to a report, and how to find related WMI
information from your WMI data.
Exercise 4: Listing Local Users and Groups

Scenario
Corporate regulations require that you maintain an inventory of local users and groups on
computers in your domain for audit purposes.

The main tasks for this exercise are carried out on WINDOWS7and are as follows:
1. Find the WMI classes used to retrieve local users and groups.
2. Generate a report showing all local user accounts and groups from all computers in your
domain. This report should contain the WMI object class to identify the object type as well as the
computer name, user or group name, and SID.

� Task 1: Find the WMI classes used to retrieve local users and groups
1. Search for WMI classes representing local users in the default namespace using Get-
WmiObject.
2. Search for WMI classes representing local groups in the default namespace using Get-
WmiObject.
� Task 2: Generate a local users and groups report
1. Retrieve a list of all local user accounts on the local computer and identify the properties
containing the WMI object class name, the computer name, the user name, and the SID.
2. Retrieve a list of all local groups on the local computer and identify the properties containing
the WMI object class name, the computer name, the user name, and the SID.
3. Read the basic help information for the ForEach-Object cmdlet. Note that ForEach-Object
allows you to process a collection of objects one at a time.
4. Generate a single table showing all local users and groups from all computers in the
[Link] file that is in your documents folder. Format the table output so that it contains
only the object type, the computer name, the user or group name, and the SID.

Hint: If you want to include two (or more) independent shell commands into a single {script block},
separate the commands by using a semicolon.

Results: After this exercise, you should be able to retrieve local user and group account information from
local and remote computers and generate a report combining this information into a single table.

Common questions

Powered by AI

The ForEach-Object cmdlet in PowerShell is utilized when iteratively processing each object in a collection for tasks like generating reports on local users and groups. Each object can be individually accessed and manipulated, allowing for actions such as data extraction, transformation, and construction of report rows. This approach is essential when combining data from numerous sources, ensuring comprehensive dataset processing and inclusion in structured outputs such as tables .

WMI classes and namespaces can be discovered on a remote computer by enumerating them using the Get-WmiObject cmdlet. Specifically, the List parameter on Get-WmiObject is used to retrieve all classes within a default namespace, while wildcards allow for searching classes and namespaces that contain specific strings like 'Printer'. This helps in quickly identifying and narrowing down relevant classes across potentially thousands of options, providing a more efficient way to work with WMI .

Format-Table is primarily for generating visually appealing, human-readable table outputs on the console, while Select-Object is optimized for selecting and preparing data for further processing or export. Select-Object is preferred for exporting to CSV because it maintains the data structure integrity without introducing formatting issues that can occur with Format-Table, ensuring seamless data parsing and integration into spreadsheets .

Maintaining an inventory of local users and groups is essential for audit and compliance purposes within corporate environments. It ensures proper access control, security monitoring, and accountability. PowerShell facilitates this by using commands like Get-WmiObject to query WMI classes representing local users and groups. Data such as object type, computer name, and SID are extracted and formatted into a report using a table, allowing administrators to comprehensively review the user and group configurations on all domain computers .

Using the Get-WmiObject cmdlet in PowerShell, you can retrieve operating system information by applying it to the Win32_OperatingSystem class. To retrieve information for multiple computers, you can utilize the -ComputerName parameter to specify the list of computers. The results can then be customized using the Select-Object cmdlet to specify required properties such as Version and ServicePack versions. Finally, these results can be exported using Export-Csv cmdlet to output to a file called Inventory.csv .

The DriveType property is integral for differentiating between disk types when retrieving logical disk information using WMI, as it designates specific integer values to associate with drive types; for instance, 3 identifies hard disks. By filtering based on DriveType, administrators can efficiently select only relevant disk information (e.g., persistent storage devices) while excluding non-storage drives like optical and floppy drives, optimizing dataset relevance for reports and actions .

Generating a logical disk report involves using Get-WmiObject to query all logical disks using the Win32_LogicalDisk class. By passing computer names into the command and using the Filter parameter to specify the DriveType as 3 (indicating hard disks), relevant data is retrieved. For calculated fields like PercentFree, you use the Select-Object cmdlet with an expression to calculate free space percentage. This involves dividing FreeSpace by Size for each disk entry, labeling this as 'PercentFree', and adding it into the report output .

Custom objects in PowerShell allow administrators to amalgamate different types of information into single coherent units for insightful reporting. By using the Select-Object cmdlet, data from multiple WMI classes can be combined into custom objects where each object includes properties like operating system details and BIOS serial numbers collected from commands like Get-WmiObject. This capability provides versatility in creating tailored reports that suit specific administrative and auditing needs .

The BIOS plays a crucial role in computer inventory systems by providing unique serial numbers, which are often used as asset tags for identification and tracking. PowerShell can retrieve these serial numbers by querying the Win32_BIOS WMI class across multiple computers. This is done by executing the Get-WmiObject cmdlet with the -ComputerName parameter to target multiple devices, combined with exporting the information to a file for record-keeping .

Disabling the Windows Firewall is necessary for these lab exercises to ensure unhindered access to remote WMI classes and namespaces required for querying and management tasks. While it facilitates communication and interaction in a controlled lab environment, in real-world settings, this could expose systems to security vulnerabilities if not managed with strict access controls and monitoring, highlighting the balance needed between operational functionality and security .

You might also like