Tutorial by Examples

All variables in powershell begin with a US dollar sign ($). The simplest example of this is: $foo = "bar" This statement allocates a variable called foo with a string value of "bar".
To remove a variable from memory, one can use the Remove-Item cmdlet. Note: The variable name does NOT include the $. Remove-Item Variable:\foo Variable has a provider to allow most *-item cmdlets to work much like file systems. Another method to remove variable is to use Remove-Variable cmdlet...
The default scope for a variable is the enclosing container. If outside a script, or other container then the scope is Global. To specify a scope, it is prefixed to the variable name $scope:varname like so: $foo = "Global Scope" function myFunc { $foo = "Function (local) scope&...
By Default, powershell would return the output to the calling Entity. Consider Below Example, Get-Process -Name excel This would simply, return the running process which matches the name excel, to the calling entity. In this case, the PowerShell Host. It prints something like, Handles NPM(K...
Powershell allows multiple assignment of variables and treats almost everything like an array or list. This means that instead of doing something like this: $input = "foo.bar.baz" $parts = $input.Split(".") $foo = $parts[0] $bar = $parts[1] $baz = $parts[2] You can simply...
Array declaration in Powershell is almost the same as instantiating any other variable, i.e. you use a $name = syntax. The items in the array are declared by separating them by commas(,): $myArrayOfInts = 1,2,3,4 $myArrayOfStrings = "1","2","3","4" Adding...

Page 1 of 1