Tackling Windows Management Instrumentation in Visual Basic .NET

Encoder Data Matrix 2d barcode in Visual Basic .NET Tackling Windows Management Instrumentation

Tackling Windows Management Instrumentation
Encoding ECC200 In Visual Basic .NET
Using Barcode encoder for .NET framework Control to generate, create ECC200 image in VS .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Scanner In VB.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
WMI objects to Gm or to Format-List * to see all of the available properties; Gm will
Code 128 Code Set B Printer In VB.NET
Using Barcode generator for Visual Studio .NET Control to generate, create Code128 image in VS .NET applications.
www.OnBarcode.com
Painting Denso QR Bar Code In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create QR Code image in .NET framework applications.
www.OnBarcode.com
also list available methods. Here s an example:
DataMatrix Maker In VB.NET
Using Barcode printer for .NET Control to generate, create DataMatrix image in .NET framework applications.
www.OnBarcode.com
USS Code 39 Printer In VB.NET
Using Barcode generator for VS .NET Control to generate, create Code39 image in .NET applications.
www.OnBarcode.com
PS C:\> gwmi win32_operatingsystem | gm TypeName: System.Management.ManagementObject#root\cimv2\Win32_Operating System Name ---Reboot SetDateTime Shutdown Win32Shutdown Win32ShutdownTracker BootDevice BuildNumber BuildType Caption CodeSet CountryCode CreationClassName MemberType ---------Method Method Method Method Method Property Property Property Property Property Property Property Definition ---------System.Managemen... System.Managemen... System.Managemen... System.Managemen... System.Managemen... System.String Bo... System.String Bu... System.String Bu... System.String Ca... System.String Co... System.String Co... System.String Cr...
Generate Universal Product Code Version A In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create UPC-A image in VS .NET applications.
www.OnBarcode.com
I-2/5 Creator In Visual Basic .NET
Using Barcode encoder for VS .NET Control to generate, create 2/5 Interleaved image in .NET framework applications.
www.OnBarcode.com
I ve truncated that output to save space, but you ll see the whole thing if you run the same command. The -filter parameter lets you specify criteria for retrieving specific instances. This can be a bit tricky to use, so here s an example of the worst-case usage:
ECC200 Printer In None
Using Barcode creation for Software Control to generate, create ECC200 image in Software applications.
www.OnBarcode.com
Scanning Data Matrix ECC200 In VB.NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
PS C:\> gwmi -class win32_desktop -filter "name='COMPANY\\Administrator'" __GENUS __CLASS __SUPERCLASS __DYNASTY __RELPATH __PROPERTY_COUNT __DERIVATION __SERVER __NAMESPACE __PATH BorderWidth Caption CoolSwitch CursorBlinkRate Description DragFullWindows GridGranularity IconSpacing IconTitleFaceName IconTitleSize IconTitleWrap Name Pattern ScreenSaverActive : : : : : : : : : : 2 Win32_Desktop CIM_Setting CIM_Setting Win32_Desktop.Name="COMPANY\\Administrator" 21 {CIM_Setting} SERVER-R2 root\cimv2 \\SERVER-R2\root\cimv2:Win32_Desktop.Name="COMPANY \\Administrator" : 1 : : : 530 : : False : : 43 : Tahoma : 8 : True : COMPANY\Administrator : 0 : False
QR Code ISO/IEC18004 Creation In Java
Using Barcode encoder for Android Control to generate, create QR Code image in Android applications.
www.OnBarcode.com
Draw QR In None
Using Barcode creator for Microsoft Word Control to generate, create QR Code image in Office Word applications.
www.OnBarcode.com
Using Get-WmiObject
Generate QR Code 2d Barcode In C#
Using Barcode encoder for VS .NET Control to generate, create QR-Code image in VS .NET applications.
www.OnBarcode.com
Generating Code 128A In Objective-C
Using Barcode generator for iPad Control to generate, create Code 128 Code Set A image in iPad applications.
www.OnBarcode.com
ScreenSaverExecutable ScreenSaverSecure ScreenSaverTimeout SettingID Wallpaper WallpaperStretched WallpaperTiled : : : : : : True : False
UPC Symbol Maker In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create UPC Symbol image in VS .NET applications.
www.OnBarcode.com
Make PDF417 In .NET
Using Barcode encoder for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
www.OnBarcode.com
There are some things you should notice about this command and its output:
Code 39 Maker In Objective-C
Using Barcode generator for iPad Control to generate, create USS Code 39 image in iPad applications.
www.OnBarcode.com
PDF 417 Decoder In .NET Framework
Using Barcode scanner for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
The filter criteria is usually enclosed in double quotation marks. The filter comparison operators aren t the normal PowerShell -eq or -like operators. Instead, WMI uses more traditional, programming-like operators, such as =, >, <, <=, >=, and <>. You can use the keyword LIKE as an operator, and when you do your comparison value can use % as a character wildcard, as in "NAME LIKE '%administrator%'". Any string comparison values are enclosed in single quotation marks, which is why the outermost quotes that contain the entire filter expression must be double quotes. Backslashes are escape characters for WMI, so when you need to use a literal backslash, as in this example, you have to use two backslashes. The output of Gwmi always includes a number of system properties. These are often suppressed by PowerShell s default display configuration, but they ll be displayed if you re deliberately listing all properties or if the class doesn t have a default. System property names start with a double underscore. Here are two particularly useful ones: __SERVER contains the name of the computer that the instance was retrieved from. This can be useful when retrieving WMI information from multiple computers at once. __PATH is an absolute reference to the instance itself, and it can be used to requery the instance if necessary.
Encode GS1 - 13 In Visual Studio .NET
Using Barcode creator for Visual Studio .NET Control to generate, create UPC - 13 image in .NET applications.
www.OnBarcode.com
GS1 - 12 Decoder In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
The cmdlet can retrieve not only from remote computers but from multiple computers, using any technique that can produce a collection of strings that contain either computer names or IP addresses, for example,
PS C:\> Gwmi Win32_BIOS -comp server-r2,server3,dc4
Computers are contacted sequentially, and if one computer isn t available, the cmdlet will produce an error, skip that computer, and move on to the next. Unavailable computers generally must time out, which means the cmdlet will pause for about 30 45 seconds until it gives up, produces the error, and moves on. Once you retrieve a set of WMI instances, you can pipe them to any -Object cmdlet, to any Format- cmdlet, or to any of the Out-, Export-, or ConvertTo- cmdlets. For example, here s how you could produce a custom table from the Win32_BIOS class:
PS C:\> Gwmi Win32_BIOS | Format-Table SerialNumber,Version -auto
Tackling Windows Management Instrumentation
In chapter 8, I showed you a technique that can be used to produce custom columns using the Format-Table cmdlet. That technique can come in handy when you wish to query a couple of WMI classes from a given computer and have the results aggregated into a single table. To do so, you create a custom column for the table, and have that column s expression execute a whole new WMI query. The syntax for the command can be confusing, but the results are impressive:
PS C:\> gwmi -class win32_bios -computer server-r2,localhost | format-table @{l='ComputerName';e={$_.__SERVER}},@{l='BIOSSerial';e={$_.SerialNumber}}, @{l='OSBuild';e={gwmi -class win32_operatingsystem -comp $_.__SERVER | sele ct-object -expand BuildNumber}} -autosize ComputerName BIOSSerial OSBuil d ------------ --------------SERVER-R2 VMware-56 4d 45 fc 13 92 de c3-93 5c 40 6b 47 bb 5b 86 7600
That syntax can be a bit easier to parse if you copy it into the PowerShell ISE and format it a bit:
gwmi -class win32_bios -computer server-r2,localhost | format-table @{l='ComputerName';e={$_.__SERVER}}, @{l='BIOSSerial';e={$_.SerialNumber}}, @{l='OSBuild';e={ gwmi -class win32_operatingsystem -comp $_.__SERVER | select-object -expand BuildNumber} } -autosize
Here s what s happening:
Get-WmiObject is querying Win32_BIOS from two computers. The results are being piped to Format-Table. Format-Table is being told to
create three custom columns: The first column is named ComputerName, and it s using the __SERVER system property from the Win32_BIOS instance. The second column is named BIOSSerial, and it s using the SerialNumber property of the Win32_BIOS instance. The third column is named OSBuild. This column is executing a whole new Get-WmiObject query, retrieving the Win32_OperatingSystem class from the __SERVER system property of the Win32_BIOS instance (of the same computer). That result is being piped to Select-Object, which is selecting just the contents of the BuildNumber property of the Win32_OperatingSystem instance and using that as the value for the OSBuild column. That s complex syntax, but it offers powerful results. It s also a great example of how much you can achieve by stringing together a few carefully selected PowerShell cmdlets. As I ve mentioned, some WMI classes include methods. You ll see how to use those in chapter 13; doing so can be a bit complicated, and the topic deserves its own chapter.
Copyright © OnBarcode.com . All rights reserved.