How to create the different types of variable

How to create the different types of variable


# An Integer (A whole Number) is created by using the whole number with no quotations #
$var1 = 1

# A double (A number with a decimal point) is created by using a number with a decimal point with no quotations #
$var1_2 = 1.20

# A string (A sequence of characters which are to be used as text) is created by starting and ending the text with single or double quotes #

$var2 = "One Two Three"
# An array (A variable that holds one or many different values) is created by starting and ending each entry with a single or double quote, each entry is split with a comma and the entire list starts with an open bracket and ends with a closing bracket #
$var3 = ('one','two','three')

# A hash table (A collection of Names and Values) is created by initiating the variable using the @{}. it is populated by using the variable name, a dot, the name of the entry, then its value #
$var4 = @{}
$var4.person = "Peter"
$var4.age = 22


# A powershell object is created by converting the hash table shown above in a custom psobject #
$var5 = New-Object -TypeName psobject -Property $var4





Comments