Microsoft PowerShell

Notes - Microsoft PowerShell Scripts
Book Author - Jeff Hicks
XXXXX


Links
Common PowerShell commands & their aliases
XXXXX
XXXXX


The Advanced PowerShell Scripting Crash Course 2019 - Learn PowerShell in less than 3 hours
Skillshare - The Advanced PowerShell Scripting Crash Course 2019
01 - Main Introduction
02 - Introduction & PowerShell Integrated Scripting Enviornment
Execution policies:

Restricted - No scripts can be run, only commands from PowerShell prompt can be executed. for compliance reasons
AllSigned - Only scripts that are signed by a trusted publisher are allowed to be executed
RemoteSigned - All downloaded scripts must be signed by a trusted publisher before they are allowed to be executed.
Unrestricted - There are no restrictions
Bypass- No scripts are blocked and no warnengs or prompts are provided.
Undefined - This removes all currently configured execution policies fromm the syste, with the exectopion of those configured by Group Policy.
get-executionpolicy, click green play button
Set-ExecutionPolicy Unrestricted
03 - Variables in powershell Edited
Variable names in PowerShell begin with a $ symbol
$name="mark"
GetType() method
Notes on Ch3
04 - Arrays & Hashtables edited
An array is a collection of elements under a single variable name
elements can be of different data types
an index of an array always starts with zero
To create an array, enter $foo = New-Object system.Collections.ArrayList
An array always starts with an index of Zero "0"
To add an item to an array $array.Add("some value")
To remove an item from an array $array.Remove("some value")
$array.Indexof("value") will output the index or position of the value.
Moving on to Hashtables
Hashtables are similar to arrays except that you are allowed to define not only its value but the key as well
Contains a key and a value
To create hashtable $cute = @{"Name"="Nicole"}
Adding multiple key value pair, separated by a semi colon: $F1Team=@{"Name"="RedBull";"Racer"="Sebastian";"UniformColor"="NavyBlue";}
Note: generate exercises to involving hashtabes & arrays
05 - CMDlets.
Get-Help. type 'get help' and than whatever it is you are working on. Type "get-help get-childitem"
get-help get-alias -examples
get-childitem - is the same as pwd(print working directory)
get-location - shows the path
get-alias - prints all the shortcuts used in powershell
set-alias -Name see -Value Get-Location (now see is the same as get-location)
get-localgroup (prints all the local groups on your computer)
get-localgroupmember -Name administrators (lists administrators)
Write-host "Hello there"
write-host "Hello there" -foregroundcolor (forgroundcolor is a flag)
write-host "Hello there" -foregroundcolor DarkBlue -backgroundcolor Yellow
write-output (same as above, but can pipe to other commandlets)
Write-output | get-member
read-host = "Hi there, what city is mars"
$planet = read-host = "Hi there, what city is mars" (this will store the prompted input to the variable "planet")
New-Item text1.txt
New-Item text2.txt
New-Item text3.txt
New-Item text4.txt
$data = Get-Content C:\users\username\contentfile.txt (copies all the data in the text file into variable $data)
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX


Notes - Microsoft PowerShell Scripts
Set-LocalUser -Name adambertram -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force)
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX