Explain the use of Windows PowerShell scripts

  

Windows PowerShell is a command-line shell and scripting environment that enables command line users and script writers to take advantage of the power of the .NET Framework. It introduces a number of very useful new concepts that further extend the knowledge and scripts you get in the Windows Command Prompt and Windows Script Host environment. This tutorial will explain the use of Windows PowerShell scripts in WMI.

WMI consists of three basic elements:

1.Provider -- Approve access to managed objects and provide a valid WMI API

2.Classes -- Objects have WMI statements for properties and methods

3.Namespace -- logical grouping of classes

So how does PowerShell make WMI access easier? So?

First, let's take a look at the tools PowerShell provides for WMI. Overall there are five PowerShell command sets, which makes WMI easy to use. I will list them all here, but I will only focus on one of them (Get-WMIObject):

1.Get-WmiObject—— return objects based on namespaces and provided categories

2.Invoke-WmiMethod—— Call WMI program (usually used to execute static programs)

3.Register-WmiEvent—— for subscribing to WMI events

4. Remove-WmiObject -- delete an instance of an existing WMI class (to be clear, it does not actually delete the class itself, but an instance of this class in memory)

5.Set-WmiInstance -- Create Or update an instance of an existing WMI class (use it cautiously because it actually writes to the WMI library)

Now let's solve the biggest problem in WMI and figure out what it is. And what data can be provided.

You can rely on the following code to write the program:

$Root = "\\\\.\\ROOT:__namespace"

$WMIProv = New-Object System.Management .ManagementClass

($Root)

$WMIProv.GetInstances() |  Select Name (However, this is more complicated than other tasks. Fortunately, you don't have to do this often.)

Here's how you can list the classes provided by a specific namespace (the default is Root\\CIM2, It includes all Microsoft Win32 classes):

# On local machine

Get-WmiObject –Namespace Root\\SecurityCenter –List

# On Remote machine

Get-WmiObject –Namespace Root\\SecurityCenter –List

–Computer core

# To filter you can use wildcards

Get-WmiObject –Namespace Root\\SecurityCenter –List

*firewall*

# To list the classes for HyperV on remote server

Get-WmiObject –Namespace Root\\Virtualization –List< Br>

–Computer core (This is very difficult, but you can cheat through WMI browser or Microsoft's PowerShell Scriptomatic and other free tools.) Previous 12 Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved