SlideShare a Scribd company logo
Practical PowerShell Programming 
for 
Professional People 
Ben Ten 
(@Ben0xA) 
Slides: http://www.slideshare.net/BenTen0xA 
BSidesDFW 2014
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
About Me 
Ben Ten (0xA) 
@Ben0xA - twitter 
Chicago - #burbsec 
Security Consultant 
Developer 
PoshSec Framework Developer / Creator 
Gamer 
Geek
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
About Me
SecurityFail 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
About Me
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
About Me
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Overview 
●Languages and Development 
●PowerShell Scripting 
●PowerShell Modules 
●ActiveDirectory 
●Resources 
●Q&A 
} 
} 2nd Hour 
1st Hour
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Overview 
Feel free to interrupt and ask questions!
Languages and Development 
Before we begin, a bit of a primer! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
●Styles of Coding 
●Syntax 
●Getting Help 
●Starting Out
Languages and Development 
Styles of Coding/Scripting/Development 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
●Novice 
●Avid Scripter 
●Full Time Developer 
●Code Monkey
Languages and Development 
Styles of Coding/Scripting/Development 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
●Novice 
●Avid Scripter 
●Full Time Developer 
●Code Monkey
Languages and Development 
Syntax 
syn•tax (sĭnˈtăksˌ) – the rules that govern 
how a script, or program, is developed in a 
given language. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Languages and Development 
Syntax 
White Space, parens (), commas, periods, 
quotes (“ vs '), tabs, braces [], curly 
brackets {}, colons :, semi-colons ;, all play 
an integral part in the syntax of a 
language! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Languages and Development 
Getting Help! 
RTF Manual/Docs/Reference 
Often times, the documentation will have 
an answer for what you are trying to 
accomplish. *NOT ALWAYS THOUGH* 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Languages and Development 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Getting Help! 
Interactive Help 
● ? 
●F1 
●Intellisense (Ctrl+Space) 
●Get-Help
Languages and Development 
Getting Help! 
Search Engines FTW! 
Google is not the end all in searches. For 
Development I prefer DuckDuckGo! 
https://duckduckgo.com 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Languages and Development 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Overview 
PowerShell is a task automation and 
configuration management framework 
from Microsoft, consisting of a command-line 
shell and associated scripting 
language built on the .NET Framework. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Overview 
PowerShell was designed by : 
● Jeffrey Snover (@jsnover) 
●Bruce Payette (@BrucePayette) 
● James Truher 
Initial release was November 14, 2006 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Overview 
PowerShell is a part of the Windows 
Management Framework. WMF 5.0 was 
released on April 3, 2014. 
For today's scripting we will be using WMF 
3.0. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
You will need: 
●Windows Management Framework 3.0 
●Microsoft .NET Framework 4.5 
●Text Editor (your choice) 
●Sublime Text http://www.sublimetext.com/ 
●Komodo Edit http://komodoide.com/komodo-edit/ 
●PowerShell ISE (comes with WMF)
PowerShell 
File Name Extensions 
.ps1 – Script Files 
.psm1 – Script Module Files 
.psd1 – Script Manifest Files 
.ps1xml – Formatting and Type Files 
.dll - Cmdlet and Provider Assemblies 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
File Name Extensions 
.ps1 – Script Files 
.psm1 – Script Module Files 
.psd1 – Script Manifest Files 
.ps1xml – Formatting and Type Files 
.dll - Cmdlet and Provider Assemblies 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Cmdlets, Functions, and Scripts Oh My! 
From a functional standpoint, cmdlets, 
functions, and scripts are practically the 
same. 
They are a way to call a specific block of 
code. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Cmdlet: 
Written in a compiled .NET language. 
Easier to deploy. 
Help files are easier to write. 
Has support for parameter validation. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Function: 
Written in a PowerShell language. 
Has to be deployed with a library. 
Help is written inside the function. 
Parameter validation has to be done in the 
function itself. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Script: 
Written in a PowerShell language. 
Is invoked by calling the .ps1 file. 
Deployed by itself or in a manifest file. 
Can contain functions. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Set-ExecutionPolicy 
Before you can run your custom scripts 
you have to set the ExecutionPolicy to 
RemoteSigned. 
In PowerShell type: 
Set-ExecutionPolicy RemoteSigned 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
HelloWorld.ps1 
Enough of the primer! Let's get coding! 
This is where you code along with me if 
you can! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Variable(s): 
a symbolic name associated with a value 
and whose associated value may be 
changed. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Hard-Coded: 
Typing the value directly into your script. 
Our “Hello World” text was hard-coded. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
PowerShell Variables: 
A PowerShell variable is defined with the 
dollar sign $ followed by the name of the 
variable. 
For example: $message is a variable. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
PowerShell Variables: 
Let's rewrite our HelloWorld.ps1 to use a 
variable $message with our text “Hello 
World”. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Strong vs Weak Typing: 
$a = 1 weak type 
[int]$a = 1 strong type 
[String]$a = “1”
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Quotes! Single vs Double 
Double Quotes (“) will attempt to resolve 
any variables before anything is printed to 
the screen. 
Single Quotes (') will print exactly what is 
typed between the quotes. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Backtick ` 
The backtick, or grave accent, is a special 
escape character. This means that you 
want the next character to be printed and 
not interpreted in anyway. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
HelloWorld.ps1 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Getting Input 
Write-Output is great. But how do you get 
information from a user? 
Read-Host 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Getting Input 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Getting Input 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
A Condition is: 
a feature of a programming language 
which perform a different set of 
computations or actions depending on 
whether a programmer-specified boolean 
condition evaluates to true or false. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
A Condition is: 
Is the stop light is green? Keep going. 
Is the stop light is red? Stop. 
Is the stop light is yellow? Floor it!!!! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
A Condition expressed: 
● If - Beginning of the condition. 
●Else - Evaluates only if preceding condition(s) 
is(are) false. 
●ElseIf – Evaluates if preceding condition(s) 
is(are) false with a new condition. 
●Switch – Multiple conditions for a single 
variable or object. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
A Conditional Operator: 
-and = both conditions must be true. 
-or = only one of the conditions must be 
true. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
A Conditional Operator: 
-eq = Equals 
-lt = Less Than 
-gt = Greater Than 
-ne = Not Equal 
-ge = Great Than or Equal 
-le = Less Than or Equal
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
A Conditional Operator: 
-Like 
-NotLike 
-Match 
-NotMatch 
-Contains 
-NotContains 
-In 
-NotIn 
-Replace
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Operator Precedence: 
When operators have equal precedence, 
Windows PowerShell evaluates them from 
left to right. The exceptions are the 
assignment operators, the cast operators, 
and the negation operators (!, -not, -bnot), 
which are evaluated from right to left. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Operator Precedence: 
You can use enclosures, such as 
parentheses, to override the standard 
precedence order and force Windows 
PowerShell to evaluate the enclosed part 
of an expression before an unenclosed 
part. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Conditional Logic 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Parameters 
A Parameter is: 
A variable that allows you to pass an 
object to a Cmdlet, Function, or Script. 
Get-ChildItem 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Parameters 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Parameters 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Get-Help Get-ChildItem 
Get-ChildItem [[-Path] <String[]>] [[-Filter] <String>] [-Exclude <String[]> 
[-Name] [-Recurse] [-UseTransaction [<SwitchParameter>]] 
[<CommonParameters> 
Get-ChildItem [[-Filter] <String>] [-Exclude <String[]>] [-Force] [-Include 
-LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] 
[<CommonParame 
Get-ChildItem [-Attributes <FileAttributes]>] [-Directory] [-File] [-Force] 
[-UseTransaction] [<CommonParameters>]
Parameters 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Parameters 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Objects vs Text 
PowerShell is Object Based. 
Even if you see text on the screen, that 
text is actually a “String” object. 
You can access the members of the object 
using the . operator after the variable 
name. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Objects vs Text 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Piping 
Piping is: 
a way of moving something, unchanged, 
from one place to another.
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Piping 
Piping is represented by the | (pipe) 
character. 
A pipe takes the object from the left side 
and passes it to the right side. 
Note: When passing to another cmdlet, $_ 
is used to reference the passed object.
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Piping
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Loops 
Loops: 
A way to perform the same block of code 
for a specific number of times, until a 
specific condition is met, or while a 
specific condition exists.
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Loops 
Loops: 
●ForEach 
●ForEach-Object 
●For 
●While 
●Do While 
●Do Until
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Loops
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Loops
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Loops
Comments 
Comments are defined by the # symbol. 
Block comments are enclosed with <# and 
#>. 
.SYNOPSIS 
.DESCRIPTION 
.PARAMETER 
.EXAMPLE 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Comments 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Putting it all Together 
The final script! 
Requirements: 
●Search all files. 
●Find the ones that were modified in a 
specific date range. 
●Create a list of those files and display 
them. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Short Break! 
Be back in 10 minutes! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Add Parameters for Date 
Use Param () block to Add Parameters. 
Get-Help about_Parameters 
Param( 
[Parameter(Mandatory=$true)] 
[Date]$FromDate, 
) 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Add Parameters for Date 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Add Parameters for Date 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Add Parameters for Date 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Add Parameters for Date 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
File Name Extensions 
.ps1 – Script Files 
.psm1 – Script Module Files 
.psd1 – Script Manifest Files 
.ps1xml – Formatting and Type Files 
.dll - Cmdlet and Provider Assemblies 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
PowerShell 
File Name Extensions 
.ps1 – Script Files 
.psm1 – Script Module Files 
.psd1 – Script Manifest Files 
.ps1xml – Formatting and Type Files 
.dll - Cmdlet and Provider Assemblies 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module 
Making Changes to Modules 
●Must use -Force parameter when using 
Import-Module for a module that is 
already loaded into the session.
Import-Module -Force 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Module 
Note on Compiled Modules (DLLs) 
●You can not import a compiled module in 
an active PowerShell RunSpace after it 
was already imported. 
●You have to close the RunSpace and open 
it again.
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
File I/O 
Get-Content <filename> 
●Export-CliXML, Export-Csv, Export- 
FormatData 
●Out-File, Out-Csv, Out-Data
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
File I/O 
Let's create a script that will read each line 
of a CSV file, and write out only the first 
delimited column.
ActiveDirectory 
ActiveDirectory PowerShell Module 
●Available in the RSAT 
●Comes Standard on Server (2008, 2012) 
●Windows 8 Note: Must use pkgmgr to 
install the .cab file. 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Yes, you can do this the hard way... 
Here's an example. 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
But why do it the hard way? 
Get-Command -Module ActiveDirectory 
135 Commands! 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Get-AdUser 
●Query the domain controller. 
●Get-Help Get-AdUser
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
New-ADUser 
●Adds a new user to the domain. 
●Disabled by default!
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
New-ADUser 
●We can add a user with very few 
parameters, but that user is not “usable”. 
●Need -DisplayName -SAMAccountName
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
ActiveDirectory 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Remove-ADUser 
●Uses the DN to remove the specified user. 
●Remove-ADUser “CN=Ben 
Ten,CN=Users,DC=dfw,DC=local”
Final Script 
Take what you have learned and write a 
PowerShell Function called Import-Users 
●Imports Users from csv file Users.txt 
●Must force Password Reset 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Error Handling 
Try / Catch / Finally Blocks are used to 
catch exceptions. 
Try { 
} 
Catch [Type] { 
} 
Finally { 
} 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Error Handling 
ErrorVariable / ErrorAction are also used 
but in a different way. 
Get-Help about_CommonParameters 
Do-Something -ErrorVariable $err 
-ErrorAction [Continue | Ignore | Inquire | 
SilentlyContinue | Stop] 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Homework 
Go back to your Import-User function. Add 
Error Handling for when: 
1. The DC is not responding. 
2. The line you are trying to import is not 
delimited correctly. 
3. The user already exists. 
Practical PowerShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Pitfalls 
Don't overuse the Pipe! Not everything has 
to be done in a single line. 
It's more important that you understand 
the code before you try to condense it to a 
single line.
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
Pitfalls 
With Loops, start small then open the 
valve all the way! 
You can get more than you wanted, or get 
stuck in an endless loop. 
Especially true when doing File operations!
Resources 
Freenode (irc.freenode.net) 
#PowerShell, #pssec, #poshsec channels. 
Learn Windows PowerShell in a Month of 
Lunches ~ Don Jones 
Carlos Perez – PowerShell Workshop at 
BSidesDFW. 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Resources 
PoshSec – https://github.com/PoshSec 
PoshSec Framework 
PowerSploit – 
https://github.com/mattifestation/ 
Posh-SecMod – 
https://github.com/DarkOperator/ 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Resources 
http://www.slideshare.net/BenTen0xA/ 
practical-powershell-programming-for-professional- 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
people
Resources 
http://www.slideshare.net/BenTen0xA/ 
practical-powershell-programming-for-professional- 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA) 
people
Matt Johnson (mwjcomputing) 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Follow these People! 
@mwjcomputing 
@securitymoey 
@jaysonstreet 
@BSidesDFW 
@tonikjdk 
@darkoperator 
@mattifestation 
@obscuresec 
@harmj0y 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Contact - Q&A 
Ben Ten (0xA) 
@Ben0xA - twitter 
http://ben0xa.com 
https://poshsec.org 
web@ben0xa.com 
Ben0xA – LinkedIn, Github, keybase, etc. 
irc.freenode.net 
#burbsec, #poshsec, #pssec 
http://www.slideshare.net/BenTen0xA 
QUESTIONS?! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Thank You! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)
Thank You! 
Practical Powe rShell Programming for Professional People 
BSidesDFW - Ben Ten (@Ben0xA)

More Related Content

What's hot

WordPress for the modern PHP developer
WordPress for the modern PHP developerWordPress for the modern PHP developer
WordPress for the modern PHP developer
Chris Sherry
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
Adam Culp
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
Tareq Hasan
 
DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007
Tim Bunce
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
Adam Englander
 
Theory and practice – migrating your legacy code into our modern test drive...
Theory and practice – migrating your  legacy code into our modern test  drive...Theory and practice – migrating your  legacy code into our modern test  drive...
Theory and practice – migrating your legacy code into our modern test drive...
Lars Jankowfsky
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
John Anderson
 
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
Heejong Ahn
 
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radioAncient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
Cristopher Ewing
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
Jacques Woodcock
 
Alfanous Quran Search Engine API
Alfanous Quran Search Engine APIAlfanous Quran Search Engine API
Alfanous Quran Search Engine API
Assem CHELLI
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)
Kousuke Ebihara
 
RESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an IntroductionRESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an Introduction
Miredot
 

What's hot (13)

WordPress for the modern PHP developer
WordPress for the modern PHP developerWordPress for the modern PHP developer
WordPress for the modern PHP developer
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007DBI for Parrot and Perl 6 Lightning Talk 2007
DBI for Parrot and Perl 6 Lightning Talk 2007
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
Theory and practice – migrating your legacy code into our modern test drive...
Theory and practice – migrating your  legacy code into our modern test  drive...Theory and practice – migrating your  legacy code into our modern test  drive...
Theory and practice – migrating your legacy code into our modern test drive...
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
 
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radioAncient To Modern: Upgrading nearly a decade of Plone in public radio
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
 
Alfanous Quran Search Engine API
Alfanous Quran Search Engine APIAlfanous Quran Search Engine API
Alfanous Quran Search Engine API
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)
 
RESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an IntroductionRESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an Introduction
 

Viewers also liked

Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
Office 365 & PowerShell - A match made in heaven
Office 365 & PowerShell - A match made in heavenOffice 365 & PowerShell - A match made in heaven
Office 365 & PowerShell - A match made in heaven
Sébastien Levert
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
ÇözümPARK
 
PowerShell Plus v4.7 Overview
PowerShell Plus v4.7 OverviewPowerShell Plus v4.7 Overview
PowerShell Plus v4.7 Overview
Richard Giles
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
Roo7break
 
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
Richard Calderon
 
PowerShell from *nix user perspective
PowerShell from *nix user perspectivePowerShell from *nix user perspective
PowerShell from *nix user perspective
Juraj Michálek
 
Managing Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShellManaging Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShell
guesta849bc8b
 
PowerShell UIAtomation
PowerShell UIAtomationPowerShell UIAtomation
PowerShell UIAtomation
Juraj Michálek
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Incorporating PowerShell into your Arsenal with PS>Attack
Incorporating PowerShell into your Arsenal with PS>AttackIncorporating PowerShell into your Arsenal with PS>Attack
Incorporating PowerShell into your Arsenal with PS>Attack
jaredhaight
 
Getting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingGetting Started With PowerShell Scripting
Getting Started With PowerShell Scripting
Ravikanth Chaganti
 
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Puppet
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Salaudeen Rajack
 
Geek Sync | Using PowerShell with Python and SQL Server
Geek Sync | Using PowerShell with Python and SQL ServerGeek Sync | Using PowerShell with Python and SQL Server
Geek Sync | Using PowerShell with Python and SQL Server
IDERA Software
 
Network Mapping with PowerShell
Network Mapping with PowerShellNetwork Mapping with PowerShell
Network Mapping with PowerShell
Costin-Alin Neacsu
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration Testers
Nikhil Mittal
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
44CON
 
Some PowerShell Goodies
Some PowerShell GoodiesSome PowerShell Goodies
Some PowerShell Goodies
Cybereason
 

Viewers also liked (20)

Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
Office 365 & PowerShell - A match made in heaven
Office 365 & PowerShell - A match made in heavenOffice 365 & PowerShell - A match made in heaven
Office 365 & PowerShell - A match made in heaven
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
PowerShell Plus v4.7 Overview
PowerShell Plus v4.7 OverviewPowerShell Plus v4.7 Overview
PowerShell Plus v4.7 Overview
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
 
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
 
PowerShell from *nix user perspective
PowerShell from *nix user perspectivePowerShell from *nix user perspective
PowerShell from *nix user perspective
 
Managing Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShellManaging Virtual Infrastructures With PowerShell
Managing Virtual Infrastructures With PowerShell
 
PowerShell UIAtomation
PowerShell UIAtomationPowerShell UIAtomation
PowerShell UIAtomation
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Incorporating PowerShell into your Arsenal with PS>Attack
Incorporating PowerShell into your Arsenal with PS>AttackIncorporating PowerShell into your Arsenal with PS>Attack
Incorporating PowerShell into your Arsenal with PS>Attack
 
Getting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingGetting Started With PowerShell Scripting
Getting Started With PowerShell Scripting
 
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Geek Sync | Using PowerShell with Python and SQL Server
Geek Sync | Using PowerShell with Python and SQL ServerGeek Sync | Using PowerShell with Python and SQL Server
Geek Sync | Using PowerShell with Python and SQL Server
 
Network Mapping with PowerShell
Network Mapping with PowerShellNetwork Mapping with PowerShell
Network Mapping with PowerShell
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration Testers
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
 
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
44CON London 2015 - Old Dog, New Tricks: Forensics With PowerShell
 
Some PowerShell Goodies
Some PowerShell GoodiesSome PowerShell Goodies
Some PowerShell Goodies
 

Similar to Practical PowerShell Programming for Professional People - Extended Edition

Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
Cisco Russia
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
KALAISELVI P
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
Satish Verma
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
Mattupallipardhu
 
Introducing Language-Oriented Business Applications - Markus Voelter
Introducing Language-Oriented Business Applications - Markus VoelterIntroducing Language-Oriented Business Applications - Markus Voelter
Introducing Language-Oriented Business Applications - Markus Voelter
JAXLondon2014
 
Govind.ppt.pptx
Govind.ppt.pptxGovind.ppt.pptx
Govind.ppt.pptx
ShivKaushik8
 
Vbox7 presentation 2019
Vbox7 presentation 2019Vbox7 presentation 2019
Vbox7 presentation 2019
Emilian Sartonev
 
resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016
Jason Barr
 
Prersentation
PrersentationPrersentation
Prersentation
Ashwin Deora
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Entrepreneur’s guide to programming
Entrepreneur’s guide to programmingEntrepreneur’s guide to programming
Entrepreneur’s guide to programming
Chris Callahan
 
[WebCamp2014] Towards functional web
[WebCamp2014] Towards functional web[WebCamp2014] Towards functional web
[WebCamp2014] Towards functional web
Blaž Repas
 
vb script
vb scriptvb script
vb script
Anand Dhana
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?
mikaelbarbero
 
PowerShell Zero To Hero Workshop!
PowerShell Zero To Hero Workshop!PowerShell Zero To Hero Workshop!
PowerShell Zero To Hero Workshop!
Daisy Stevens
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
iimjobs and hirist
 
Elasticsearch Basics
Elasticsearch BasicsElasticsearch Basics
Elasticsearch Basics
Shifa Khan
 
Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!
Chang W. Doh
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
AhmedAElHalimAhmed
 

Similar to Practical PowerShell Programming for Professional People - Extended Edition (20)

Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Introducing Language-Oriented Business Applications - Markus Voelter
Introducing Language-Oriented Business Applications - Markus VoelterIntroducing Language-Oriented Business Applications - Markus Voelter
Introducing Language-Oriented Business Applications - Markus Voelter
 
Govind.ppt.pptx
Govind.ppt.pptxGovind.ppt.pptx
Govind.ppt.pptx
 
Vbox7 presentation 2019
Vbox7 presentation 2019Vbox7 presentation 2019
Vbox7 presentation 2019
 
resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016
 
Prersentation
PrersentationPrersentation
Prersentation
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
 
Entrepreneur’s guide to programming
Entrepreneur’s guide to programmingEntrepreneur’s guide to programming
Entrepreneur’s guide to programming
 
[WebCamp2014] Towards functional web
[WebCamp2014] Towards functional web[WebCamp2014] Towards functional web
[WebCamp2014] Towards functional web
 
vb script
vb scriptvb script
vb script
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?
 
PowerShell Zero To Hero Workshop!
PowerShell Zero To Hero Workshop!PowerShell Zero To Hero Workshop!
PowerShell Zero To Hero Workshop!
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
 
Elasticsearch Basics
Elasticsearch BasicsElasticsearch Basics
Elasticsearch Basics
 
Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 

Practical PowerShell Programming for Professional People - Extended Edition

  • 1. Practical PowerShell Programming for Professional People Ben Ten (@Ben0xA) Slides: http://www.slideshare.net/BenTen0xA BSidesDFW 2014
  • 2. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) About Me Ben Ten (0xA) @Ben0xA - twitter Chicago - #burbsec Security Consultant Developer PoshSec Framework Developer / Creator Gamer Geek
  • 3. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) About Me
  • 4. SecurityFail Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 5. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) About Me
  • 6. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) About Me
  • 7. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Overview ●Languages and Development ●PowerShell Scripting ●PowerShell Modules ●ActiveDirectory ●Resources ●Q&A } } 2nd Hour 1st Hour
  • 8. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Overview Feel free to interrupt and ask questions!
  • 9. Languages and Development Before we begin, a bit of a primer! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) ●Styles of Coding ●Syntax ●Getting Help ●Starting Out
  • 10. Languages and Development Styles of Coding/Scripting/Development Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) ●Novice ●Avid Scripter ●Full Time Developer ●Code Monkey
  • 11. Languages and Development Styles of Coding/Scripting/Development Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) ●Novice ●Avid Scripter ●Full Time Developer ●Code Monkey
  • 12. Languages and Development Syntax syn•tax (sĭnˈtăksˌ) – the rules that govern how a script, or program, is developed in a given language. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 13. Languages and Development Syntax White Space, parens (), commas, periods, quotes (“ vs '), tabs, braces [], curly brackets {}, colons :, semi-colons ;, all play an integral part in the syntax of a language! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 14. Languages and Development Getting Help! RTF Manual/Docs/Reference Often times, the documentation will have an answer for what you are trying to accomplish. *NOT ALWAYS THOUGH* Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 15. Languages and Development Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Getting Help! Interactive Help ● ? ●F1 ●Intellisense (Ctrl+Space) ●Get-Help
  • 16. Languages and Development Getting Help! Search Engines FTW! Google is not the end all in searches. For Development I prefer DuckDuckGo! https://duckduckgo.com Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 17. Languages and Development Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 18. PowerShell Overview PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 19. PowerShell Overview PowerShell was designed by : ● Jeffrey Snover (@jsnover) ●Bruce Payette (@BrucePayette) ● James Truher Initial release was November 14, 2006 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 20. PowerShell Overview PowerShell is a part of the Windows Management Framework. WMF 5.0 was released on April 3, 2014. For today's scripting we will be using WMF 3.0. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 21. PowerShell Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) You will need: ●Windows Management Framework 3.0 ●Microsoft .NET Framework 4.5 ●Text Editor (your choice) ●Sublime Text http://www.sublimetext.com/ ●Komodo Edit http://komodoide.com/komodo-edit/ ●PowerShell ISE (comes with WMF)
  • 22. PowerShell File Name Extensions .ps1 – Script Files .psm1 – Script Module Files .psd1 – Script Manifest Files .ps1xml – Formatting and Type Files .dll - Cmdlet and Provider Assemblies Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 23. PowerShell File Name Extensions .ps1 – Script Files .psm1 – Script Module Files .psd1 – Script Manifest Files .ps1xml – Formatting and Type Files .dll - Cmdlet and Provider Assemblies Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 24. PowerShell Cmdlets, Functions, and Scripts Oh My! From a functional standpoint, cmdlets, functions, and scripts are practically the same. They are a way to call a specific block of code. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 25. PowerShell Cmdlet: Written in a compiled .NET language. Easier to deploy. Help files are easier to write. Has support for parameter validation. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 26. PowerShell Function: Written in a PowerShell language. Has to be deployed with a library. Help is written inside the function. Parameter validation has to be done in the function itself. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 27. PowerShell Script: Written in a PowerShell language. Is invoked by calling the .ps1 file. Deployed by itself or in a manifest file. Can contain functions. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 28. PowerShell Set-ExecutionPolicy Before you can run your custom scripts you have to set the ExecutionPolicy to RemoteSigned. In PowerShell type: Set-ExecutionPolicy RemoteSigned Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 29. PowerShell Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 30. PowerShell HelloWorld.ps1 Enough of the primer! Let's get coding! This is where you code along with me if you can! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 31. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 32. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 33. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 34. HelloWorld.ps1 Variable(s): a symbolic name associated with a value and whose associated value may be changed. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 35. HelloWorld.ps1 Hard-Coded: Typing the value directly into your script. Our “Hello World” text was hard-coded. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 36. HelloWorld.ps1 PowerShell Variables: A PowerShell variable is defined with the dollar sign $ followed by the name of the variable. For example: $message is a variable. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 37. HelloWorld.ps1 PowerShell Variables: Let's rewrite our HelloWorld.ps1 to use a variable $message with our text “Hello World”. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 38. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 39. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 40. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 41. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 42. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Strong vs Weak Typing: $a = 1 weak type [int]$a = 1 strong type [String]$a = “1”
  • 43. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 44. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 45. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 46. HelloWorld.ps1 Quotes! Single vs Double Double Quotes (“) will attempt to resolve any variables before anything is printed to the screen. Single Quotes (') will print exactly what is typed between the quotes. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 47. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 48. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 49. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 50. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 51. HelloWorld.ps1 Backtick ` The backtick, or grave accent, is a special escape character. This means that you want the next character to be printed and not interpreted in anyway. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 52. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 53. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 54. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 55. HelloWorld.ps1 Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 56. Getting Input Write-Output is great. But how do you get information from a user? Read-Host Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 57. Getting Input Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 58. Getting Input Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 59. Conditional Logic A Condition is: a feature of a programming language which perform a different set of computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 60. Conditional Logic A Condition is: Is the stop light is green? Keep going. Is the stop light is red? Stop. Is the stop light is yellow? Floor it!!!! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 61. Conditional Logic A Condition expressed: ● If - Beginning of the condition. ●Else - Evaluates only if preceding condition(s) is(are) false. ●ElseIf – Evaluates if preceding condition(s) is(are) false with a new condition. ●Switch – Multiple conditions for a single variable or object. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 62. Conditional Logic A Conditional Operator: -and = both conditions must be true. -or = only one of the conditions must be true. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 63. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) A Conditional Operator: -eq = Equals -lt = Less Than -gt = Greater Than -ne = Not Equal -ge = Great Than or Equal -le = Less Than or Equal
  • 64. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) A Conditional Operator: -Like -NotLike -Match -NotMatch -Contains -NotContains -In -NotIn -Replace
  • 65. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 66. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 67. Conditional Logic Operator Precedence: When operators have equal precedence, Windows PowerShell evaluates them from left to right. The exceptions are the assignment operators, the cast operators, and the negation operators (!, -not, -bnot), which are evaluated from right to left. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 68. Conditional Logic Operator Precedence: You can use enclosures, such as parentheses, to override the standard precedence order and force Windows PowerShell to evaluate the enclosed part of an expression before an unenclosed part. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 69. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 70. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 71. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 72. Conditional Logic Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 73. Parameters A Parameter is: A variable that allows you to pass an object to a Cmdlet, Function, or Script. Get-ChildItem Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 74. Parameters Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 75. Parameters Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Get-Help Get-ChildItem Get-ChildItem [[-Path] <String[]>] [[-Filter] <String>] [-Exclude <String[]> [-Name] [-Recurse] [-UseTransaction [<SwitchParameter>]] [<CommonParameters> Get-ChildItem [[-Filter] <String>] [-Exclude <String[]>] [-Force] [-Include -LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<CommonParame Get-ChildItem [-Attributes <FileAttributes]>] [-Directory] [-File] [-Force] [-UseTransaction] [<CommonParameters>]
  • 76. Parameters Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 77. Parameters Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 78. Objects vs Text PowerShell is Object Based. Even if you see text on the screen, that text is actually a “String” object. You can access the members of the object using the . operator after the variable name. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 79. Objects vs Text Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 80. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Piping Piping is: a way of moving something, unchanged, from one place to another.
  • 81. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Piping Piping is represented by the | (pipe) character. A pipe takes the object from the left side and passes it to the right side. Note: When passing to another cmdlet, $_ is used to reference the passed object.
  • 82. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Piping
  • 83. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Loops Loops: A way to perform the same block of code for a specific number of times, until a specific condition is met, or while a specific condition exists.
  • 84. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Loops Loops: ●ForEach ●ForEach-Object ●For ●While ●Do While ●Do Until
  • 85. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Loops
  • 86. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Loops
  • 87. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Loops
  • 88. Comments Comments are defined by the # symbol. Block comments are enclosed with <# and #>. .SYNOPSIS .DESCRIPTION .PARAMETER .EXAMPLE Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 89. Comments Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 90. Putting it all Together The final script! Requirements: ●Search all files. ●Find the ones that were modified in a specific date range. ●Create a list of those files and display them. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 91. Short Break! Be back in 10 minutes! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 92. Add Parameters for Date Use Param () block to Add Parameters. Get-Help about_Parameters Param( [Parameter(Mandatory=$true)] [Date]$FromDate, ) Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 93. Add Parameters for Date Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 94. Add Parameters for Date Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 95. Add Parameters for Date Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 96. Add Parameters for Date Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 97. PowerShell File Name Extensions .ps1 – Script Files .psm1 – Script Module Files .psd1 – Script Manifest Files .ps1xml – Formatting and Type Files .dll - Cmdlet and Provider Assemblies Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 98. PowerShell File Name Extensions .ps1 – Script Files .psm1 – Script Module Files .psd1 – Script Manifest Files .ps1xml – Formatting and Type Files .dll - Cmdlet and Provider Assemblies Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 99. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module
  • 100. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module
  • 101. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module
  • 102. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module
  • 103. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module Making Changes to Modules ●Must use -Force parameter when using Import-Module for a module that is already loaded into the session.
  • 104. Import-Module -Force Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 105. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Module Note on Compiled Modules (DLLs) ●You can not import a compiled module in an active PowerShell RunSpace after it was already imported. ●You have to close the RunSpace and open it again.
  • 106. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) File I/O Get-Content <filename> ●Export-CliXML, Export-Csv, Export- FormatData ●Out-File, Out-Csv, Out-Data
  • 107. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) File I/O Let's create a script that will read each line of a CSV file, and write out only the first delimited column.
  • 108. ActiveDirectory ActiveDirectory PowerShell Module ●Available in the RSAT ●Comes Standard on Server (2008, 2012) ●Windows 8 Note: Must use pkgmgr to install the .cab file. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 109. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 110. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 111. ActiveDirectory Yes, you can do this the hard way... Here's an example. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 112. ActiveDirectory But why do it the hard way? Get-Command -Module ActiveDirectory 135 Commands! Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 113. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 114. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Get-AdUser ●Query the domain controller. ●Get-Help Get-AdUser
  • 115. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 116. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) New-ADUser ●Adds a new user to the domain. ●Disabled by default!
  • 117. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 118. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 119. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) New-ADUser ●We can add a user with very few parameters, but that user is not “usable”. ●Need -DisplayName -SAMAccountName
  • 120. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 121. ActiveDirectory Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Remove-ADUser ●Uses the DN to remove the specified user. ●Remove-ADUser “CN=Ben Ten,CN=Users,DC=dfw,DC=local”
  • 122. Final Script Take what you have learned and write a PowerShell Function called Import-Users ●Imports Users from csv file Users.txt ●Must force Password Reset Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 123. Error Handling Try / Catch / Finally Blocks are used to catch exceptions. Try { } Catch [Type] { } Finally { } Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 124. Error Handling ErrorVariable / ErrorAction are also used but in a different way. Get-Help about_CommonParameters Do-Something -ErrorVariable $err -ErrorAction [Continue | Ignore | Inquire | SilentlyContinue | Stop] Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 125. Homework Go back to your Import-User function. Add Error Handling for when: 1. The DC is not responding. 2. The line you are trying to import is not delimited correctly. 3. The user already exists. Practical PowerShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 126. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Pitfalls Don't overuse the Pipe! Not everything has to be done in a single line. It's more important that you understand the code before you try to condense it to a single line.
  • 127. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) Pitfalls With Loops, start small then open the valve all the way! You can get more than you wanted, or get stuck in an endless loop. Especially true when doing File operations!
  • 128. Resources Freenode (irc.freenode.net) #PowerShell, #pssec, #poshsec channels. Learn Windows PowerShell in a Month of Lunches ~ Don Jones Carlos Perez – PowerShell Workshop at BSidesDFW. Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 129. Resources PoshSec – https://github.com/PoshSec PoshSec Framework PowerSploit – https://github.com/mattifestation/ Posh-SecMod – https://github.com/DarkOperator/ Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 130. Resources http://www.slideshare.net/BenTen0xA/ practical-powershell-programming-for-professional- Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) people
  • 131. Resources http://www.slideshare.net/BenTen0xA/ practical-powershell-programming-for-professional- Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA) people
  • 132. Matt Johnson (mwjcomputing) Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 133. Follow these People! @mwjcomputing @securitymoey @jaysonstreet @BSidesDFW @tonikjdk @darkoperator @mattifestation @obscuresec @harmj0y Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 134. Contact - Q&A Ben Ten (0xA) @Ben0xA - twitter http://ben0xa.com https://poshsec.org web@ben0xa.com Ben0xA – LinkedIn, Github, keybase, etc. irc.freenode.net #burbsec, #poshsec, #pssec http://www.slideshare.net/BenTen0xA QUESTIONS?! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 135. Thank You! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)
  • 136. Thank You! Practical Powe rShell Programming for Professional People BSidesDFW - Ben Ten (@Ben0xA)