Power Shell Video Tutorials
Wednesday, October 4, 2017
Tuesday, October 3, 2017
Lecture 3: Learn to securely use Passwords with PowerShell
This video series review passwords
Lesson 1
www.boldzebras.com
1. $un = "tim@gmail.com"
*create user name
2. $pw = "Password"
*create password
3. $sp = $pw = New-Object System.Management.Automation.PSCredential -ArgumentList $un, $pw
4. Connect-msolService -credential $plainCred
*couldn't run this due to not having access to Office 365
Lecture 2:Objects in PowerShell
This lecture / video is about objects and we run through a sample script
Script to work tthrough
Get-PSDrive | ?{$_.Free -gt 1} | %{$Count = 0; Write-Host "";} { $_.Name + ": Used: " + "{0:N2}" -f ($_.Used/1gb) + " Free: " + "{0:N2}" -f ($_.free/1gb) + " Total: " + "{0:N2}" -f (($_.Used/1gb)+($_.Free/1gb)); $Count = $Count + $_.Free;}{Write-Host"";Write-Host "Total Free Space " ("{0:N2}" -f ($Count/1gb)) -backgroundcolor magenta}
1. get-psdrives
*all the drives on local
Note: some drives are irrelevant
2. break apart script ?
*ask a question
3. Get-PSDrive | where-object {$_.Free -gt 1}
*(verb)(command)(noun)(pipe)(where object){(current object in the pipe)(greater than)(1)}
**it is passing the variable property (amount of space) into .Free then returning if greater than one
4. Get-PSDrive | where-object {$_.Free -gt 1} | select-object Root, Used, Free
**Select Object Properties
5. Get-PSDrive | where-object {$_.Free -gt 1} | ForEach-Object {"zebra"}
*runs though each object and assigns console.writeline("zebra")
6. Get-PSDrive | where-object {$_.Free -gt 1} | ForEach-Object {write-host " Free space for" $_.Free " is" $_.Root -foregroundcolor red }
* note, all text must contain "" and no commas after varibales
7.Get-PSDrive | where-object {$_.Free -gt 1} | ForEach-Object {write-host " Free space for"( $_.Free/1gb) " is" $_.Root -foregroundcolor red }
* Can divide by 1gb or 1mb
8."{0:N0}" -f 1000000000
**Note it is zero's in the formatting equation
9. "{0:N2}" -f 1000000000
*returns .00
10. "{0:c2}" -f 1000000000
*returns currency
11. "{0:p2}" -f 1000000000
*percent
12.Get-PSDrive | where-object {$_.Free -gt 1} | ForEach-Object {write-host " Free space for"("{0:N0}" -f ($_.Free/1gb)) " is" $_.Root -foregroundcolor red }
*added into statement
13. ?
*is an alias for where-object
14. %
*foreach alias
15. foreach [19:48]
foreach{$c=0; write-host "blah hblah"}{$c=$c+1;write-host"blah, blah"}{$c
Lecture 1: Getting Started: Transcripts, Variables, Methods, Properties
Lecture 1: Getting Started
Video 1: starts with getting PowerShell all setup. I changed the background to black and the font to neon green, just like the a400 hack days. Font 24 size
Part 1: Getting Started
1. Always start out with command
Start-Transcript
*allows script to be saved
2. get-command
*everything available in PS
3. get-
(verb)(command)(noun)
*everything in PowerShell must be in this format
**noun= parameter
4. Other examples
get-command-Noun service
*returned 8 objects about service
5. get-help get-service
* this is the help section
6. get-help get-service -examples -online
* good command to show examples
7. cls
*(alias) clears screen
**translate alias get-alias cls
***returns -> Clear-Host
****this is: (verb)(command)(noun)
8. get-process
*this is similar to task manager
9. pipe over command (|)
*| denotes pipe
10. get-member
*denotes all the properties and methods of that object
**properties: example car: color, type, brand
***methods: open door, start car, break car
11. | select-object *
(pipe)(verb)(command)(noun)(all)
Part 2: Variables
1. $zebra = get-process MicrosftEdge
*(variable) = (verb)(command)(noun) (object)
2.$zebra
*check to see if variable was set
3. $zebra.name
*(variable).(property)
4. $zebra.kill()
*(variable).(Method)
5. get-history
*what we did
6. transcripts located in documents folder
Subscribe to:
Posts (Atom)