Platinum Sponsor
Views
Archives

PowerCLI: Lesson #3

Ok last week I was in Russia so I missed out on the weekly lesson. In this lesson I want to demonstrate the idea of how PowerShell is object orientated. Just about everything you work with in PowerShell is an object and objects have members known as properties and methods (actions). I’m going to use a very common analogy to get the idea of objects across using the tried and test “objects are like a bicycle” method.

Here is a picture of a bicycle.

 

There is something very common about bikes they usually have the same parts (properties) and usually perform the same actions(methods). So common parts include wheel, seat, pedals and brake. Whilst common actions include move forward, steer left, steer right and brake. So if a bicycle was a PowerShell command or an object you were working with like a VM then you would expect to work with its properties and methods.

 

In comparison if we where to look at some examples of the properties of Get-VM cmdlet object we might expect to see:

 

So a property of a VM might be the amount memory allocated to VM is found by view the MemoryMB property.

To find out what type of properties and methods (members) an object or cmdlet has you could pipe the cmdlet through the Get-Member cmdlet or using its alias gm

 

 So we haven’t really talked about any new PowerCLI cmdlets this lesson so let’s spend some time learning a few new commands.

Let’s look at useful command that can help you work out which Get- cmdlets that are used with the PowerCLI (vmware). If you filter the Get-Command cmdlet to search on verbs that start with “get” that are associated with vmware module.

 

So right near the top is the Get-Cluster cmdlet. If we run it we get the default output which is all the clustered associated to the vSphere vCenter implementation that we are connected to.

 

If we look at the properties of Get-Cluster we manipulate its Drsmode property for example to see the automation level set for DRS. One way we can do this is by passing the result (an object) into a variable which is also an object. We can the view the details of this variable by looking at its properties. We’ll talk about variables in more detail in another lesson. For now just know to define a variable you just declare it by placing a $ sign in front of a meaningful word then making it equal to the said object which in our case is the result (an object) of running the Get-Cluster cmdlet.

 

 Now we can view its DRSmode property.

 

Ok you can look around the rest of the Get- (PowerCLI) cmdlets as homework. Try not to do anything destructive at this stage 😉 and that concludes lesson 3.

PreviousNext

Leave a Reply

Gold Sponsors
Silver Sponsors