PowerShell processing objects

From "Windows Powershell Getting Started Guide"

Processing object

  Although you may not realize it at first, when working in Windows PowerShell, you are using .NET objects . As your experience increases, the ability to deal with objects becomes more obvious, and you find that you are using objects and even thinking with objects.
  
  Technically speaking, .NET objects are instances of .NET classes that contain data and the operations associated with that data . However, you can think of objects as data entities with properties (similar to properties) and methods (operations that can be performed on the object) .
  
  For example, when you get a service in Windows PowerShell, you actually get the object that represents the service. When viewing information about a service, you are viewing the properties of its service object. In addition, when the service is started (that is, when the Status property of the service is changed to "started"), the method of the service object is used.
  
  All objects of the same type have the same properties and methods, but each instance of the object may have different property values. For example, each service object has Name and Status properties. However, each service can have a different name and different status.
  
  When you are ready, it is easy to understand the object. To find out what type of object the cmdlet is getting, use the pipeline operator (|) to send the result of the "get" command to the Get-Member command. For example, the following command sends the objects retrieved by the Get-Service command to Get-Member.

Get-Service | Get-Member

  Get-Member displays information about the service object, including the type name of the object and a list of its properties and methods.

   TypeName:System.ServiceProcess.ServiceController

Name                      MemberType    Definition
----                      ----------    ----------
Name                      AliasProperty Name = ServiceName
RequiredServices          AliasProperty RequiredServices = ServicesDependedOn
Disposed                  Event         System.EventHandler Disposed(System.Object, Sys...
Close                     Method        void Close()
Continue                  Method        void Continue()

  To get information about the object class, copy and paste the type name in MSDN, such as
System.ServiceProcess.ServiceController. After you find the class, you can read the MSDN subtopic to learn about the properties and methods of objects based on the class (such as objects in Windows PowerShell).
  
  To find the values ​​of all properties of a specific object, use the pipeline operator (|) to send the result of the "get" command to the Format-List or Format-Table command. Use the Property parameter of the format cmdlet with all the values ​​(*).
  
For example, to find all attributes of the WinRM service on the system, type:

Get-Service WinRM | Format-List -Property *

An example of the results is shown below.

Name                : WinRM
RequiredServices    : {RPCSS, HTTP}
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : False
DisplayName         : Windows Remote Management (WS-Management)
DependentServices   : {}
MachineName         : .
ServiceName         : WinRM
ServicesDependedOn  : {RPCSS, HTTP}
ServiceHandle       :
Status              : Stopped
ServiceType         : Win32OwnProcess, Win32ShareProcess
StartType           : Automatic
Site                :
Container           :

  When you first learn Windows PowerShell, you don't need to know anything about objects, but you need to be aware of the concept. You will soon be able to make the most of the object.

Return to my PowerShell study notes

Guess you like

Origin blog.51cto.com/3chou/2562902