User Tools

Site Tools


public:common_patterns_in_powershell

This is an old revision of the document!


Common patterns in PowerShell

Defining an empty list

You can define an empty list like so:

$a = @()

And you can add items by:

$a += ,$item

Creating custom objects

To more conveniently manage or output data while using Powershell, it is often useful to use custom objects. They can be created as follows:

$Person = [PSCustomObject]@{
    FullName = "Thomas De Reyck"
    Age = 37
    Job = "IT technician"
}

When you output the created object afterwards, we can see our own custom fields:

> $Person
 
FullName        Age Job
--------        --- ---
Thomas De Reyck  37 IT technician
public/common_patterns_in_powershell.1713355631.txt.gz · Last modified: by thomas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki