Академический Документы
Профессиональный Документы
Культура Документы
2
Overview
Windows PowerShell
• Version 1 was released in 2006
• Jeffrey Snover is the Architect of PowerShell
• It’s not a scripting language
• Command-line shell for command-line utilities
• Like all good shells it has scripting capabilities
4
Overview
• As of 16AUG2016
•Open Source Alpha for Linux and Mac
5
Overview
• As of 16AUG2016
•This Tweet followed the announcement
6
Overview
7
Overview
Windows PowerShell
• Comprised of:
• PowerShell.exe
• PowerShellISE.exe
• Integrated Scripting Environment
•Not installed by default on older Server Versions
•Use Add-WindowsFeature powershell-ise
8
Version
• $PSVersionTable
9
Exercise 1
10
Version
11
Version
12
Version
13
Your Mileage May Vary
14
Overview
15
Overview
16
Exercise 2 Update To PS Version 4
– wusa.exe PS4Installer.msu
– Reboot
17
Exercise 3 Version
18
Font
• ISE
• Use font slider
• Customize the window as you see fit
20
Console
21
ISE
22
Help
• The error will tell you exactly where you went wrong
– It really is useful
• Updateable Help
• Update-help
• Wildcards
• Help *log*
• Help *event*
23
Help
24
Help
• Get-Member
25
Exercise 4
• Updateable Help
• Update-help
26
Exercise 5 Show-Command
27
Show-Command
28
Exercise 6
• Get-Command
• Get-Command | More
• Space bar - One Page at a Time
• Return - One Command at a Time
• Ctrl-C Exits
29
Exercise 6 Cont
• Get-Command
30
Exercise 7 Command Line
31
Exercise 7 Command Line
32
Exercise 8 Piping and Exporting
• Dir | More
– Works as you would expect
33
Exercise 8 Cont Piping and Exporting
34
Exercise 8 Cont Piping and Exporting
35
Killing and Stopping Services
• Stop-Service
• Start-Service
• Set-Service
36
Exercise 9 Aliases
• New-Alias
• Help New-Alias -examples
37
Exercise 10 Another Output
• Get-Process | Out-Gridview
38
Yet Another Output
39
Registry Access Exercise 11
• PS C:> cd hklm:
• hklm:\> dir
• hklm:\> cd \system\currentcontrolset\control
• hklm:\> dir | more
• hklm:\> powershell
40
Remoting Into Another Machine
41
Remoting Into Another Machine
42
Remoting Into Another Machine
43
Remoting Into Another Machine
• Kerberos Authentication
44
Remoting Into Another Machine
45
Remoting Into Another Machine
46
Remoting Into Another Machine
47
Remoting Into Another Sys Exercise 12
• Enable-PSRemoting
• Runs on the Client
• New-PSSession <IP or Name> -Credential
<Name>
• Runs on the CC system
48
Remoting Sys Exercise 12 Cont
• Enable-PSRemoting
• Runs on the Client
• New-PSSession <IP> -Credential <UserName>
• Runs on the CC system
• Starts a new session and runs it in the
background on a CC system
– After session start the ID will be presented
• WinRM, by default, won’t let you connect
via IP Addy or a DNS Alias
• Enter-PSSession #
• To enter that session
49
Remoting Sys Exercise 12 Cont
• Get-ExecutionPolicy
• Should be set to Restricted
• Set-ExecutionPolicy
• Unrestricted
• This actually changes HKEY_LOCAL_MACHINE
50
Remoting Into Another Machine
• PowerShell Security...
52
Remoting Into Another Machine
53
Remoting Into Yet Another Machine
55
Invoke versus Remoting
• Invoke-Command -ComputerName
<computername> -FilePath <pathToScript>
-ArgumentList <argument 1, 2, 3>
56
Invoke Exercise 14
• Local machine
• PS C:\Users\Administrator>
57
Invoke Exercise 14 Cont
• PS C:\Users\Administrator>
58
Invoke Exercise 14 Cont
• PS C:\Users\Administrator>
59
Invoke to Multiple Machines
• 1:n Remoting
• Send a command to multiple remote computers
at the same time
• Each system will independently execute the
command and send the results back to you
• By default, PowerShell can talk to 32 computers
at once
• I could use -ThrottleLimit to increase that
number...
60
Invoke to Multiple Machines
61
Invoke to Multiple Machines
62
Setting Trusted Hosts
63
Exercise 15 Cleaning up
• PS C:\Users\Administrator>
• Get-PSSession
• Remove-PSSession #
• Alias
• Set-ScheduledJob
– Cmdlet for running virtually any PowerShell
script at a specific time or on a predetermined
schedule.
– Version 4.0 adds the parameter RunNow to
Set-ScheduledJob Cmdlet
– New-JobTrigger and Set-JobTrigger cmdlets
is RepeatIndefinitely, for jobs you want to
start, and run forever.
65
Hash
• Get-FileHash
– Cmdlet will compute a hash of any file(s) you
pass to it.
– Choose which algorithm is used to compute
the hash.
• The default hashing algorithm in SHA256, but you can
use any of these:
● SHA1 / SHA256 / SHA384 / SHA512 / MACTripleDES / MD5 / RIPEMD160
• get-filehash svchost.exe
66
APT Anyone?
• This is APT
67
More?
68
Notes
• New-PSSession localhost
– Enter-PSSession
69
Lab
70