Powershell on the Way to Work–Part 8


Ok feeling better today.   Today we’re going to quickly touch on “Objects”.

Now before all of you IT Pros go running into a corner screaming and casting oil slicks beyond you, we are NOT opening up Visual Studio.   But we are going to touch lightly on a topic that is important to be aware of when using Powershell. 

No, you will not get tested on this.  Really it’s not that bad either.

Let’s think in Dos terms first.

In DOS we did this to set a variable

SET THISTHING=A Whole pile of words I am staring at on the screen

or

SET THISOTHERTHING=55

If you had to look at that and try to describe it, what would you say it was?  Really.

I would say it would a bunch of letters.  But to describe it further it isn’t just a BUNCH of letters, it is a Number of letters. Or I might describe the other one as a number. Visually to ME it appears to be a number.

If I was to have certain applications in Dos that could manipulate that data, I would have some Methods at my hand.

Really that’s an Object.   The way we would look at that particular information as a WHOLE is an Object and what we can do to it.   (Ok all of you Developers peeking in, this is a REEEEEAALLY simplified explanation, so please stop laughing) Winking smile

Is your brain spinning a bit?  Let’s look at this Powershell Variable I’m going to make.

$BrainHurts=’Please Stop Talking About Objects.  Our brains are spinning.’

In Windows Powershell anything that is stored in a variable is just an object.  That’s all.   To see what is attached to this object we pull out the almighty Powershell Canopener for viewing what’s attached to an Object called GET-MEMBER

We ‘re going to “Pipe” that variable into GET-MEMBER.  Piping is a term you should be familiar with in Dos land.

$BrainHurts | GET-MEMBER

It will give us something like this

image

What is tell us looking up is that $BrainHurts is a String (System.String).   There’s a pile of methods (Think built in applications you can use to manipulate what $BrainHurts has) and maybe some extra information like “Length”.

image

Do you really care?  If you try to echo it on the screen it will still work.   But understanding that everything in Windows Powershell is an object is important.  It is so much of the Power it contains.   Later on when we touch on Active Directory and understand that each user is an Object, GET-MEMBER will be a way to see what “properties” that user has (IE: Group Membership, Account Expiry, Last Logged on Date)

We’ll touch on Objects sometime later.   For now, I’ll put the Genie back into the bottle (GET IN THERE GENIE!  *WHAP!*) and we’ll turn to some basics.   I’ll show you the first Cmdlet I ran into that made working with Active Directory a breeze.   EXPORT-CSV.

Chat soon everyone, time to get back on the road (which is a lousy place by the way for Ballroom dancing)

DSC_0158 (640x425)_thumb

Sean Kearney
Twitter: @energizedtech
www.powershell.ca

Comments (0)

Skip to main content