PowerShell 4.0 introduces desired state configuration (DSC),
a powerful new feature that makes it easier than ever to manage your Windows
infrastructure, whether on premise or in the cloud. DSC is built on the Common
Information Model (CIM) standard developed by the Desktop Management Task Force
(DMTF) and uses Windows Remote Management (WinRM) technology as a communication
mechanism. In this post we will look at what Windows Remote Management is and
how it is used in the Windows OS world to enable standards-based management. In
the upcoming posts I'll explain how CIM cmdlets in PowerShell use WinRM to work
with management data from remote systems and the role of DSC in managing remote
machines.
Windows Remote
Management is the Microsoft implementation of the WS-Management Protocol.
It uses SOAP (Simple Object Access Protocol) for exchanging control information
and data between capable devices over HTTP and HTTPS. The main goal of
WS-Management-based implementation is to provide a common way for these systems
or components to access and exchange information.
The WinRM sevice enables remote management of windows
systems. You can use the cmdlet given below to check the status of the service
on the computer.
Get-Service -ComputerName 'MyComputerXXX' -Name WinRM
If the service is not enabled on the computer, you can
create a listener based on HTTP or HTTPS protocol on the desired port. To setup
a WinRM listener you can use the Set-WSManQuickConfig cmdlet. Once WinRM
listener is set and working, you can use the infrastructure to access
management information from remote servers.
The CIM cmdlets introduced as part of PowerShell 3.0 makes
it easier to work with Windows Management Instrumentation. CIM - Common Information Model is the DMTF
standard for describing the structure and behavior of managed resources such as
storage, network, or software components. The CIM standard defines two parts:
- Schema: Provides the actual model descriptions
- Infrastructure: Defines the standards for integrating multiple management models using OOPS constructs and design.
The CIM cmdlets support multiple ways of exploring WMI. They
work well when you are working in an interactive fashion. For example, Tab
expansion expands the namespace when you use the CIM cmdlets; thereby
permitting exploring namespaces that might not otherwise be very discoverable.
You can even use this technique to drill down into namespaces. For e.g if you
want to find all the classes in the root/Microsoft namespace. use the cmdlet.
You can try out tab completion after typing in the –Namespace option for the
cmdlet.
Get-CimClass -Namespace root/Microsoft
To create an instance of a class, you can use the Get-CimInstance
cmdlet. For example, the below given command, exposes all properties for the
class MSFT_WmiError
Get-CimClass -ClassName MSFT_WmiError | ForEach-Object
{$_.CimClassProperties}
You can also use the –ComputerName or –CimSession parameters
to manage remote machines. Its recommended to use the CimSession and reuse the
session if you are trying to perform a large set of operations on the remote
server.
For e.g. you can use the commands given below to get the
details of the processes running on the remote server:
$session = New-CimSession –ComputerName XXX
Get-CimInstance –ClassName Win32_Process –CimSession $session
Once we have the CIM sessions set up and the command
execution is complete, we can remove the existing CIM sessions, by using the
Remove-CimSession cmdlet.
No comments:
Post a Comment