In this post we will be going through the use of variables, arrays and hash table.
Variables are object that are created temporarily in the PowerShell console or created as part of script that are removed once the console is closed. There are system variables that are part of PowerShell but we will just be covering user variables in this post.
Variables are $ sign with a name.
We can then call the variable by using the name

There are two type of quotation marks single will only display the text between the quotes. We can use these for variable that have text data.

With double quotation marks we can passthrough text but also passthrough a variable. If we try to add a variable without double quotes it will just write the variable name and not the text in the variable.

There are some instance where we need to create a subexpression using $() around the variable to pass through specific data.
In the below I want to return just the first folder. The first command return all the folder names.
The second command is using a subexpression, we are then able to return the first folder name.

An array is pretty similar to a variable the only really difference is that it has multiple objects broken up by using comma’s.

We can also use @() to create any array if there is text other than number we have to use quotes.

We can also create a blank array, I use these when doing reports and want to output data from a script.

We will go more in depth on using the blank array in a future post but I mostly use them with hash tables.
Next we will go through using a hash table, these are like array but there is key / value pair.
Below we have a table where we created a name, surname and role heading and set a value for each.

We can also use array or variables in hash tables

This is where hash tables can come in hand for doing reports as we can output the results of multiple commands using a blank array and a hash table, then export the results to a CSV, text or html file.
We will cover both these in later post.
In this post we covered create variables, types of quotes and there uses, array’s and hash tables with some examples of each.