0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 56min

0 / 8 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

PowerShell Modules

• 58min

0 / 7 lessons complete

Powershell Challenges

• 1hr 55min

0 / 23 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

Objects, Properties and Methods Part 3

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

Now let’s take a look at using the Properties of an object

  • Let’s use the get-childitem command. First type get-childitem | gm PIPE OPERATOR (hold your shift key down and press the key right above the enter key

Then Type GM press enter

We want to use the creationtime property to find out the creation date of the current version of PowerShell, press return

Let’s type the command then I’ll explain it.

Type (Get-ChildItem $pshome\PowerShell.exe).creationtime 

  • The most common way to get the values of the properties of an object is to 

use the dot method. That means that you first surround the parameter and the path with parenthesis. Then insert a (.) then the property. Which in this case is creationtime. Now press return

And we get Wednesday, April 11, 2018 07:35 PM 

  • By the way $pshome is the path to the PowerShell home folder

Another way to get the properties of an object is to use the select-object command. The select-object command has a parameter called –property that will get the properties of an object. 

Let’s type help Select-object -showwindow and let’s analyze the syntax.

  • The parameter that we are going to be using is called -property.

Select-object is the name of the cmdlet.

Notice that the parameter -property and the argument’s value type - called object,

both are surrounded by square brackets. That means that both parameter and argument are optional and not needed. 

Notice also that -property is surrounded by a separate set of square brackets so -property is positional as well. 

We can verify that by scrolling up and looking at the parameter attributes. Which tell us that -property has a position of 0, and it is not required. 

That tells us that -property should be located in the first position in the lineup of parameters. 

We can also see that the argument has two square brackets inside the two angle brackets this means that the parameter -property can take multiple argumentsseparated by a comma. 

  • We’ll use get-eventlog security and select-object for this demonstration

Instead of displaying the whole security log let’s just display the newest 6 events.

Type Get-eventlog -logname security -newest 6

  • Now let’s use Get-member, which will show us the properties and methods

Type Get-eventlog -logname security -newest 6 | get-member

  • Let’s select a few useful properties. How about Time-Generated, EventID and machinename

Type Get-eventlog -logname security -newest 6 | Select-object Source, TimeWritten, machinename, Message. And press return.

And we see that the command ran.

In case your’e wondering why I used -logname, because as we discussed earlier it’s optional and not needed. Here’s why, when your’e first starting out in PowerShell, you might want to go ahead and type out some of the optional parameters. Especially if you plan on saving your commands and one liner’s as scripts for later use. It just makes it easier to remember what these commands and parameters are doing if you go ahead and type them out. The same goes for aliases you can use gsv for get-service . But it’s a whole lot easier to remember what get-service -name BITS is doing instead of gsv bits. Both commands will work, but when you’ve type out the whole command it’s easier to understand especially when you’re first starting with PowerShell.

Thanks for watching and we will see you in the next lecture.

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments