Unlock the Power of WMI Commands: Troubleshooting and Optimization Made Easy
WMI, which stands for Windows Management Instrumentation, is a powerful tool allowing administrators to manage Windows systems locally and remotely. It provides a deeper level of information and control than standard PowerShell commands. For instance, while the Get-Service command in PowerShell can retrieve service details, WMI commands can provide even more properties related to those services.
Here is a collection of my favorite WMI Commands
WMI Commands: Retrieve All Properties of Services
Get-WmiObject -Class Win32_Service | Select-Object *
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.
WMI Commands: Determine the Last Boot Up Time
$os = gwmi win32_operatingsystem $os.ConvertToDateTime($os.LastBootUpTime)
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:
$os.ConvertToDateTime($os.LastBootUpTime).toshortdatestring()
This will return a concise date format, like “24/10/2017”.
List Services that Start Automatically and are Running
Get-WmiObject -Class Win32_Service -Filter "state = 'running' and startmode = 'auto'" | Select-Object name, startmode, description | Format-table -AutoSize
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.
Retrieve BIOS Information
Get-WmiObject -Class Win32_Bios
This command fetches information about the system’s BIOS using the Win32_Bios
class.
Obtain Computer Information
Get-WmiObject Win32_Computersystem | Format-List Name, manufacturer, model, SystemType
This command details the computer system, such as its name, manufacturer, model, and system type.
Get Video Card Information
Get-WmiObject Win32_VideoController
This command retrieves basic information about the video card using the Win32_VideoController
class.
For a more detailed report on the video card:
$ComputerName = "localhost"
foreach ($Computer in $ComputerName)
{
$ComputerVideoCard = Get-WmiObject Win32_VideoController -ComputerName $Computer
$Output = New-Object -TypeName PSObject
Foreach ($Card in $ComputerVideoCard)
{
$Output | Add-Member NoteProperty "$($Card.DeviceID)_Name" $Card.Name
$Output | Add-Member NoteProperty "$($Card.DeviceID)_Vendor" $Card.AdapterCompatibility
$Output | Add-Member NoteProperty "$($Card.DeviceID)_PNPDeviceID" $Card.PNPDeviceID
$Output | Add-Member NoteProperty "$($Card.DeviceID)_DriverVersion" $Card.DriverVersion
$Output | Add-Member NoteProperty "$($Card.DeviceID)_VideoMode" $Card.VideoModeDescription
}
$Output
}
This script fetches detailed information about the video card, such as its name, vendor, PNP device ID, driver version, and video mode description.
In Conclusion
WMI commands are an indispensable tool in a system administrator’s arsenal. By leveraging their power, you can gain deep insights into your systems, automate repetitive tasks, and proactively address potential issues. While the examples provided here are just a starting point, the possibilities with WMI are virtually limitless.
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!
For more Tech Quicky’s – check out the rest of our blogs
Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.
Recent Comments