Powershell For Penetration Testing : Part 3
Powershell not run script by default so use following because set-Executionpolicy is set restricted
help set-Executionpolicy
get-Executionpolicy
- Restricted — Scripts won’t run.
- RemoteSigned - Scripts created locally will run, but those downloaded from the Internet will not (unless they are digitally signed by a trusted publisher).
- AllSigned - Scripts will run only if they have been signed by a trusted publisher.
- Unrestricted - Scripts will run regardless of where they have come from and whether they are signed.
set-Executionpolicy <policy name>
set-Executionpolicy Unrestricted
read and write on terminal
Read-Host "Enter Comp"
write-output "yeh"
parameter in script
param (
[Parameter(Mandatory=$true)][string]$ComputerName
)
foreach loop
Foreach ($a in $service)
{
---
}
use property
using "."
Variable
$a = Get-Process
$a = (Get-Process | Sort-Object ID)
The @ symbol
By using the @ symbol, you can turn the contents of a list into an array. For example, take the following line of code, which creates a variable named $Procs that contains multiple lines of text (an array):
$procs = @{name="explorer","svchost"}
You can also use the @ symbol when the variable is used, to ensure that it is treated as an array rather than a single value. For instance, the line of code below will run the Get-Process cmdlet against the variable I defined a moment ago. In doing so, Windows will display all the processes used by Windows Explorer and Svchost. Notice how the @ symbol is being used in front of the variable name rather than the dollar sign that we usually see used:
Get-Process @procs
Split
"Hey hasky, how are you" -split " "
The result would look like this:
Heyhasky,howareyou
Join
"Brien","Posey" -join " "
Breakpoint
The easiest way to insert a breakpoint is by line number. For instance, to insert a break point on the 10th line of a script, you could use a command like this:
New-PSBreakpoint -Script C:\Scripts\Script.ps1 -Line 10
You can also bind a breakpoint to a variable. So if you wanted your script to break any time the contents of a$ changed, you could use a command like this one:
New-PSBreakpoint -Script C:\scripts\Script.ps1 -variables a
Notice that I didn’t include the dollar sign after the variable name.
There are a number of verbs you can use with PSBreakpoint including New, Get, Enable, Disable, and Remove.
I hope You like this
happy Hacking… ;)