Hello everyone.

I often do training or work in PowerShell, and one thing I always forget is how to create an empty array.

I usually spend some time searching the net, without luck, and always end up opening an old script, and get the code from there!

On place to start with array info is this one:


It has all the info you need also how to create an empty array.

$a = @()

That’s it!

and now you can add more to it by using +=

another great tip is to always use this method when adding to an array

$user = "user info"

$array += ,$user

Notice the , in front of $user, this makes sure that even though $array might not be an array at this time (might be null if it was not initialized), we make sure that this $user string is added to a array collection, and not inserted as the value of $array.