PowerShell 5.1 and 7.x language concepts. In-memory illustrative examples; no remote systems or files are changed.
Research-based; no hands-on test claim.Start with the access pattern
If you need to process a list of server names in order, an array is a natural fit. If you repeatedly ask who owns a named server, a hashtable expresses that lookup. If each server has a name, owner and environment, an object makes those fields explicit.
Do not choose a structure because its syntax is shortest. Think about missing values, duplicate keys, ordering and the shape expected by the next command. A report with inconsistent property names is harder to validate than one with a defined record layout.
Build a small record deliberately
The example creates a sequence, a lookup and a record. The names are fictional. Array positions start at zero. Hashtable keys identify entries; assigning the same key again replaces its value, so a hashtable is not a safe way to preserve duplicate observations.
Use an ordered dictionary when the insertion order of keys matters. An ordinary hashtable should not be relied on for presentation order. Use Select-Object with an explicit property list when preparing an export so the output contract is visible.
$servers = @('app01', 'db01')
$owners = @{ app01 = 'Operations'; db01 = 'Database team' }
$record = [pscustomobject]@{
Name = $servers[0]
Owner = $owners['app01']
Environment = 'Lab'
}
$record | Select-Object Name, Owner, EnvironmentKeep collections predictable
PowerShell often unwraps a pipeline result containing one item. Wrap a result in @() when downstream logic requires array behaviour for zero, one or many results. Test all three cases. Avoid repeatedly appending to a large fixed-size array with += in a tight loop; use pipeline collection or an appropriate generic list after measuring the workload.
Multidimensional arrays have fixed dimensions and are different from an array containing arrays. For uneven groups of records, nested collections or objects are often easier to understand. If you use a matrix, document which dimension represents which entity and test the boundary indexes.
Validate before exporting or acting
Check required properties, value types and uniqueness before a report drives changes. A missing owner is a data-quality failure, not an empty string to silently accept. Keep numbers as numbers until presentation, especially if you will sort or calculate totals.
Format-Table is for display, not the middle of an export pipeline. Retain the original objects until you reach a presentation or serialisation step. If you later use the records to change systems, add explicit target validation and a separate approval or dry-run stage.