Learn

As stated in the previous exercise, properties are characteristics of an object. Just like a radius is an attribute that describes a circle and horsepower describes a car, we have properties that describe an object.

To discover just the properties of an object, we can add -MemberType Property to the Get-Member cmdlet. For example, consider the string "hello":

PS > "hello" | Get-Member -MemberType Property TypeName: System.String Name MemberType Definition ---- ---------- ---------- Length Property int Length {get;}

The example above pipes the string “hello” to Get-Member -MemberType Property. As we can see, string-type objects have a property called Length, which holds the number of characters in a string, as shown below.

PS > "hello".Length 5

Instructions

1.

Terminal exercises in this lesson use the Check Work button. Perform the tasks and click the Check Work button to move through the instructions. You can advance to the next task or exercise if you accomplish the task correctly.

In the PowerShell terminal, create a variable called $name and assign your name to it as a string.

Click the Check Work button to continue.

2.

Show all properties and methods of the variable $name.

We will see names, member types, and definitions of all properties and methods for this string-type variable.

Click the Check Work button to continue.

3.

Show only the properties of the variable $name.

Click the Check Work button to continue.

4.

Use the Length property to get the length of the $name variable.

Click the Check Work button to continue.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?