# Powershell

<table border="1" id="bkmrk-verb-noun-structure-" style="border-collapse: collapse; width: 100%; height: 239.334px;"><colgroup><col style="width: 49.9474%;"></col><col style="width: 49.9474%;"></col></colgroup><tbody><tr style="height: 29.9167px;"><td style="height: 29.9167px;">Verb-Noun</td><td style="height: 29.9167px;">Structure</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">Verb-N...</td><td style="height: 29.9167px;">Tab for intellisense</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">Stop-Service &lt;inputObject&gt; </td><td style="height: 29.9167px;">Parameters are required</td></tr></tbody></table>

Example:

Get-Eventlog -LogName System -Newest 5 | Format-List Out-File c:\\log.txt

#### Remote Access via Powershell

<table border="1" id="bkmrk-winrm-quickconfig-br" style="border-collapse: collapse; width: 100%; height: 255.2px;"><colgroup><col style="width: 49.881%;"></col><col style="width: 49.881%;"></col></colgroup><tbody><tr style="height: 29.8px;"><td style="height: 29.8px;">winrm quickconfig</td><td style="height: 29.8px;">brings the service on</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Get-Process -ComputerName SVR</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Stop-Process</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Get-Service -ComputerName SVR</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 46.6px;"><td style="height: 46.6px;">Invoke-Command -ComputerName SVR -ScriptBlock {get-eventlog -LogName Security -Newest 5}</td><td style="height: 46.6px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Enter\_PSSession -ComputerName SVR</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Exit</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">Get-Process -ComputerName SVR,DC (runs on both)</td><td style="height: 29.8px;">  
</td></tr></tbody></table>

#### CredSSP

Scenario:

1. Logged into ServerA, remote powershell to ServerB
2. ServerB powershell command attempts to access ServerC
3. Access is denied because credentials not passed from ServerB to ServerC

Credential Security Support Provider (CredSSP)

- CredSSP caches credentials on the remote server (ServerB)
- Opens up credential theft attacks if the remote server is compromised
- Disabled by default, only enable this in trusted environments

Integrated Scripting Environment (ISE)

<table border="1" id="bkmrk-get-variable-%24number" style="border-collapse: collapse; width: 100%; height: 336.45px;"><colgroup><col style="width: 49.881%;"></col><col style="width: 49.881%;"></col></colgroup><tbody><tr style="height: 29.9167px;"><td style="height: 29.9167px;">Get-Variable</td><td style="height: 29.9167px;">  
</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">$Number1 = 5</td><td style="height: 29.9167px;">Stores the value in a new variable</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">$Number</td><td style="height: 29.9167px;">outputs 5</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">$Name = "SVR"</td><td style="height: 29.9167px;">Can now use -ComputerName $Name</td></tr><tr style="height: 46.7167px;"><td style="height: 46.7167px;">ISE</td><td style="height: 46.7167px;">opens integrated scripting environment

(click show script pane)

</td></tr><tr style="height: 46.7167px;"><td style="height: 46.7167px;">$name = Read-Host "Which computer would you like to connect to?"</td><td style="height: 46.7167px;">  
</td></tr><tr style="height: 29.9167px;"><td style="height: 29.9167px;">$log = Read-Host "Which log would you like to see?"</td><td style="height: 29.9167px;">  
</td></tr><tr style="height: 46.7167px;"><td style="height: 46.7167px;">$amount = Read-Host "How many of the newest entries would you like to see?"</td><td style="height: 46.7167px;">  
</td></tr><tr style="height: 46.7167px;"><td style="height: 46.7167px;">Get-Eventlog -ComputerName $name -LogName $log -Newest $amount</td><td style="height: 46.7167px;">  
</td></tr></tbody></table>