0
0
PowerShellscripting~10 mins

Adding properties to objects in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a new property 'Age' with value 30 to the object $person.

PowerShell
$person | Add-Member -MemberType NoteProperty -Name 'Age' -Value [1]
Drag options to blanks, or click blank then click option'
A'Age'
BNoteProperty
C$person
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using the property name instead of the value for the -Value parameter.
Confusing the -Name and -Value parameters.
2fill in blank
medium

Complete the code to add a property 'City' with value 'Seattle' to the object $employee.

PowerShell
$employee | Add-Member -MemberType [1] -Name 'City' -Value 'Seattle'
Drag options to blanks, or click blank then click option'
AScriptProperty
BNoteProperty
CAliasProperty
DPropertySet
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScriptProperty which requires a script block instead of a fixed value.
Using AliasProperty which creates an alias, not a new property.
3fill in blank
hard

Fix the error in the code to add a property 'Department' with value 'HR' to $staff.

PowerShell
$staff | Add-Member -MemberType NoteProperty -Name [1] -Value 'HR'
Drag options to blanks, or click blank then click option'
A'Department'
BDepartment
C'HR'
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the property name causes a syntax error.
Confusing the property name with the property value.
4fill in blank
hard

Fill both blanks to add a property 'Salary' with value 50000 to $worker.

PowerShell
$worker | Add-Member -MemberType [1] -Name [2] -Value 50000
Drag options to blanks, or click blank then click option'
ANoteProperty
B'Salary'
DScriptProperty
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScriptProperty instead of NoteProperty.
Not quoting the property name.
5fill in blank
hard

Fill all three blanks to add a property 'Title' with value 'Manager' to $employee.

PowerShell
$employee | Add-Member -MemberType [1] -Name [2] -Value [3]
Drag options to blanks, or click blank then click option'
ANoteProperty
B'Title'
C'Manager'
DScriptProperty
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScriptProperty instead of NoteProperty.
Not quoting the property name or value.