Here is a collection of my favorite WMI Commands
List Services that Start Automatically and are Running
This command lists all services set to start automatically and are currently running. It displays their names, start modes, and descriptions in a table format.
I try to access all attributes of the given method from any classes into the WMI.
For example, I can list the methods inside “Win32_SystemDriver ” class
Get-WmiObject -Class Win32_SystemDriver -List | Select -ExpandProperty Methods
Name InParameters OutParameters Origin Qualifiers
---- ------------ ------------- ------ ----------
StartService System.Management.ManagementBaseObject CIM_Service {MappingStrings, Override, ValueMap}
StopService System.Management.ManagementBaseObject CIM_Service {MappingStrings, Override, ValueMap}
PauseService System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
ResumeService System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
InterrogateService System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
UserControlService System.Management.ManagementBaseObject System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
Create System.Management.ManagementBaseObject System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, Static, ValueMap}
Change System.Management.ManagementBaseObject System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
ChangeStartMode System.Management.ManagementBaseObject System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
Delete System.Management.ManagementBaseObject Win32_BaseService {MappingStrings, ValueMap}
In MSDN document, Create method of the Win32_SystemDriver class has many attributes like;
uint32 Create(
[in] string Name,
[in] string DisplayName,
[in] string PathName,
[in] uint8 ServiceType,
[in] uint8 ErrorControl,
[in] string StartMode,
[in] boolean DesktopInteract,
[in] string StartName,
[in] string StartPassword,
[in] string LoadOrderGroup,
[in] string LoadOrderGroupDependencies[],
[in] string ServiceDependencies[]
);
Can I see these properties with CIM/WMI cmdlets? Also, if it is possible I want to see with their descriptions.
I’m trying to create a WMI class property in one class that references a property of an instance in another WMI class, using PowerShell. I’ve been having a hard time trying to figure out the correct properties and qualifiers to get it working.
The ‘Warranty’ property in the $className class references the $classNameElement class.
if (!(Get-CimInstance -Namespace $Namespace -ClassName $classNameElement)){
# Create a ManagementClass object bound to the WMI repository
$managementClass = New-Object System.Management.ManagementClass($namespace, [String]::Empty, $null)
# Specify the new class name
$managementClass["__CLASS"] = $classNameElement
# Add 'ID' property as a string and mark it as a key
$managementClass.Properties.Add("ID", [System.Management.CimType]::String, $false)
$managementClass.Properties["ID"].Qualifiers.Add("Key", $true)
# Add 'Name' property as a string
$managementClass.Properties.Add("Name", [System.Management.CimType]::String, $false)
# Add 'Description' property as a string
$managementClass.Properties.Add("Description", [System.Management.CimType]::String, $false)
# Add 'Type' property as a string
$managementClass.Properties.Add("Type", [System.Management.CimType]::String, $false)
# Add 'Start' property as a string
$managementClass.Properties.Add("Start", [System.Management.CimType]::String, $false)
# Add 'End' property as a string
$managementClass.Properties.Add("End", [System.Management.CimType]::String, $false)
# Create the class in the WMI repository
$managementClass.Put()
}
$managementClass = $null
if (!(Get-CimInstance -Namespace $Namespace -ClassName $className)){
# Create a ManagementClass object bound to the WMI repository
$managementClass = New-Object System.Management.ManagementClass($namespace, [String]::Empty, $null)
# Specify the new class name
$managementClass["__CLASS"] = $className
# Add Association qualifier
#$managementClass.Qualifiers.Add("Association",$true)
# Add 'Serial' property as a string and mark it as a key
$managementClass.Properties.Add("Serial", [System.Management.CimType]::String, $false)
$managementClass.Properties["Serial"].Qualifiers.Add("Key", $true)
# Add 'Country' property as a string
$managementClass.Properties.Add("Country", [System.Management.CimType]::String, $false)
# Add 'Warranty' property as a reference to the Device_WarrantyElement class
$managementClass.Properties.Add("Warranty", [System.Management.CimType]::Reference, $true)
$managementClass.Properties["Warranty"].Qualifiers.Add("CIMTYPE", "ref:Device_WarrantyElement")
# Create the class in the WMI repository
$managementClass.Put()
}
Obtain Computer Information
This command details the computer system, such as its name, manufacturer, model, and system type.
Retrieve All Properties of Services
This command provides a comprehensive view of all services on your system, including their names, statuses, startup types, and descriptions. It is valuable for troubleshooting service-related issues or optimizing system performance.
Get Video Card Information
This command retrieves basic information about the video card using the Win32_VideoController
class.
For a more detailed report on the video card:
This script fetches detailed information about the video card, such as its name, vendor, PNP device ID, driver version, and video mode description.
If you’re eager to dive deeper into the world of WMI, I encourage you to explore the extensive WMI class library and experiment with crafting your own custom queries. With practice and a bit of creativity, you’ll soon be wielding WMI commands like a seasoned pro. Remember, the key is to start small, build your skills gradually, and never hesitate to seek out additional resources and guidance when needed. Happy scripting!
Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.
Retrieve BIOS Information
This command fetches information about the system’s BIOS using the Win32_Bios
class.
Determine the Last Boot Up Time
The above command retrieves the last boot-up time of the operating system and converts it to a readable date-time format. For example, it might return “24 October 2017 09:37:51”.
To get a shorter version of the date:
This will return a concise date format, like “24/10/2017”.