0
0
PowerShellscripting~5 mins

Object arrays in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an object array in PowerShell?
An object array in PowerShell is a collection that holds multiple objects, allowing you to store and manage several items together in one variable.
Click to reveal answer
beginner
How do you create an empty object array in PowerShell?
You create an empty object array by assigning an empty array literal: $array = @().
Click to reveal answer
beginner
How can you add an object to an existing array in PowerShell?
You can add an object by using the += operator, like $array += $newObject. This appends the new object to the array.
Click to reveal answer
intermediate
What is the difference between an array and an object array in PowerShell?
An array can hold any type of data, but an object array specifically holds objects, which can have properties and methods, making them more versatile.
Click to reveal answer
beginner
How do you access the properties of objects inside an object array?
You access properties by indexing the array and then using dot notation, for example: $array[0].PropertyName.
Click to reveal answer
How do you initialize an empty object array in PowerShell?
A$array = {}
B$array = @()
C$array = []
D$array = ()
Which operator adds an object to an existing array in PowerShell?
A/=
B-=
C*=
D+=
How do you access the first object's property named 'Name' in an object array called $arr?
A$arr[0].Name
B$arr.Name[0]
C$arr->Name[0]
D$arr[Name].0
What type of elements can an object array hold in PowerShell?
AAny objects including custom objects
BOnly numbers
COnly integers
DOnly strings
What happens if you add an object to an array using += in PowerShell?
AThe array is cleared
BThe object replaces the array
CThe object is appended to the array
DAn error occurs
Explain how to create and add objects to an object array in PowerShell.
Think about starting empty and then adding items one by one.
You got /3 concepts.
    Describe how to access properties of objects stored inside an object array.
    Remember arrays use numbers to pick items, objects use names for properties.
    You got /3 concepts.