PowerShell tricks using WMI Tools _powershell

Source: Internet
Author: User

WMI is a powerful technology: simply specifying a WMI class name can return all instances of its class:

Copy Code code as follows:

Ps> Get-wmiobject-class Win32_BIOS

Smbiosbiosversion:76cn27ww
Manufacturer:lenovo
Name:76cn27ww
serialnumber:1006250300406
Version:lenovo-1

How do you know which classes it has? Here's a search tool:

Copy Code code as follows:

function Find-wmiclass
{
Param
(
[Parameter (mandatory= $true)]
$SearchTerm = ' Resolution '
)

Get-wmiobject-class *-list |
Where-object {$_. Properties.count-ge 3} |
Where-object {$_. Name-notlike ' win32_perf* '} |
Where-object {
$ListOfNames = $_. Properties | Select-object-expandproperty Name
($ListOfNames-like "* $SearchTerm *")-ne $null
} |
Sort-object-property Name
}

After you set the search criteria, your code will search for the class that contains the specified property name (you can also expand your search by wildcard characters)

The following will find all the WMI classes that contain the end of "Resolution":

Copy Code code as follows:

Ps> Find-wmiclass-searchterm *resolution

Namespace:root\cimv2

Name Methods Properties
----                                -------              ----------
cim_cachememory {SetPowerState, R ... {Access, Additionalerr ...
cim_currentsensor {SetPowerState, R ... {accuracy, availabilit ...
Cim_flatpanel {SetPowerState, R ... {availability, Caption ...
cim_memory {SetPowerState, R ... {Access, Additionalerr ...
Cim_monitorresolution {} {Caption, Description,...
cim_nonvolatilestorage {SetPowerState, R ... {Access, Additionalerr ...
cim_numericsensor {SetPowerState, R ... {accuracy, availabilit ...
Cim_pcvideocontroller {SetPowerState, R ... {Acceleratorcapabiliti ...
Cim_pointingdevice {SetPowerState, R ... {availability, Caption ...
Cim_printer {SetPowerState, R ... {availability, Availab ...
Cim_tachometer {SetPowerState, R ... {accuracy, availabilit ...
cim_temperaturesensor {SetPowerState, R ... {accuracy, availabilit ...
Cim_videocontroller {SetPowerState, R ... {Acceleratorcapabiliti ...
CIM_VideoControllerResolution {} {Caption, Description,...
cim_volatilestorage {SetPowerState, R ... {Access, Additionalerr ...
cim_voltagesensor {SetPowerState, R ... {accuracy, availabilit ...
win32_cachememory {SetPowerState, R ... {Access, Additionalerr ...
Win32_currentprobe {SetPowerState, R ... {accuracy, availabilit ...
Win32_displaycontrollerconfigura ... {} {bitsperpixel, Caption ...
Win32_memoryarray {SetPowerState, R ... {Access, Additionalerr ...
Win32_memorydevice {SetPowerState, R ... {Access, Additionalerr ...
Win32_NetworkAdapterConfiguration {enabledhcp, Rene ... {ArpAlwaysSourceRoute,...
Win32_pointingdevice {SetPowerState, R ... {availability, Caption ...
Win32_Printer {SetPowerState, R ... {Attributes, Availabil ...
Win32_PrinterConfiguration {} {bitsperpel, Caption, ...
win32_smbiosmemory {SetPowerState, R ... {Access, Additionalerr ...
Win32_temperatureprobe {SetPowerState, R ... {accuracy, availabilit ...
Win32_videoconfiguration {} {actualcolorresolution ...
Win32_VideoController {SetPowerState, R ... {Acceleratorcapabiliti ...
Win32_voltageprobe {SetPowerState, R ... {accuracy, availabilit ...

Next, you can use the class name to view its valid data:

Copy Code code as follows:

ps> Get-wmiobject-class Cim_cachememory | Select-object-property *

Experience:

In fact, there is a similar function of the graphics tool is more convenient and intuitive than this code, it is called ScriptomaticV2.

Support all versions of PowerShell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.