SlideShare ist ein Scribd-Unternehmen logo
1 von 88
Downloaden Sie, um offline zu lesen
Practical PowerShell Programming
for
Professional People
Ben Ten
(@Ben0xA)
Converge Detroit 2014
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
About Me
Ben Ten (0xA)
@Ben0xA - twitter
Chicago - #burbsec
Vice President
Security Officer
Developer
PoshSec Framework Developer / Creator
Gamer
Geek
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Overview
● Languages and Development
● PowerShell Scripting
● Resources
● Q&A
● PSA: This is mostly live code scripting in
PowerShell. Please code along with me!
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Overview
Feel free to interrupt and ask questions!
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Languages and Development
Before we begin, a bit of a primer!
● Styles of Coding
● Syntax
● Getting Help
● Starting Out
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Languages and Development
Styles of Coding/Scripting/Development
● Novice
● Avid Scripter
● Full Time Developer
● Code Monkey
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Languages and Development
Styles of Coding/Scripting/Development
● Novice
● Avid Scripter
● Full Time Developer
● Code Monkey
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Languages and Development
Getting Help!
Interactive Help
● ?
● F1
● Intellisense (Ctrl+Space)
● Get-Help
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Languages and Development
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
PowerShell
Overview
PowerShell was designed by :
● Jeffrey Snover (@jsnover)
● Bruce Payette (@BrucePayette)
● James Truher
Initial release was November 14, 2006
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
PowerShell
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)
Practical PowerShell Programming for Professional People
Converge Detroit - 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
Converge Detroit - 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
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
PowerShell
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Variable(s):
a symbolic name associated with a value
and whose associated value may be
changed.
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Hard-Coded:
Typing the value directly into your script.
Our “Hello World” text was hard-coded.
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
PowerShell Variables:
Let's rewrite our HelloWorld.ps1 to use a
variable $message with our text “Hello
World”.
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
HelloWorld.ps1
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Getting Input
Write-Output is great. But how do you get
information from a user?
Read-Host
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Getting Input
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Getting Input
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
A Conditional Operator:
-and = both conditions must be true.
-or = only one of the conditions must be
true.
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
A Conditional Operator:
-eq = Equals
-lt = Less Than
-gt = Greater Than
-ne = Not Equal
-ge = Great Than or Equal
-le = Less Than or Equal
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
A Conditional Operator:
-Like
-NotLike
-Match
-NotMatch
-Contains
-NotContains
-In
-NotIn
-Replace
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Conditional Logic
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Parameters
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Parameters
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>]
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Parameters
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Parameters
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Objects vs Text
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Piping
Piping is:
a way of moving something, unchanged,
from one place to another.
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Piping
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Piping
Practical PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Loops
Loops:
● ForEach
● ForEach-Object
● For
● While
● Do While
● Do Until
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Loops
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Loops
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Loops
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Comments
Comments are defined by the # symbol.
Block comments are enclosed with <# and
#>.
.SYNOPSIS
.DESCRIPTION
.PARAMETER
.EXAMPLE
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Comments
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Putting it all Together
The final program!
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 PowerShell Programming for Professional People
Converge Detroit - 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 PowerShell Programming for Professional People
Converge Detroit - 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!
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Resources
Freenode (irc.freenode.net)
#PowerShell, #pssec, #poshsec channels.
Learn Windows PowerShell in a Month of
Lunches ~ Don Jones
Carlos Perez – PowerShell Workshop at
DerbyCon.
Practical PowerShell Programming for Professional People
Converge Detroit - 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
QUESTIONS?!
Practical PowerShell Programming for Professional People
Converge Detroit - Ben Ten (@Ben0xA)
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
Zero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutesZero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutes
Jeremy Kendall
 

Was ist angesagt? (20)

De-mystifying contributing to PostgreSQL
De-mystifying contributing to PostgreSQLDe-mystifying contributing to PostgreSQL
De-mystifying contributing to PostgreSQL
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl ProgrammerModern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
 
Php test fest
Php test festPhp test fest
Php test fest
 
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
 
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
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
Mixing Plone and Django for explosive results
Mixing Plone and Django for explosive resultsMixing Plone and Django for explosive results
Mixing Plone and Django for explosive results
 
Getting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingGetting Started With PowerShell Scripting
Getting Started With PowerShell Scripting
 
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
 
Netflix JavaScript Talks - Scaling A/B Testing on Netflix.com with Node.js
Netflix JavaScript Talks - Scaling A/B Testing on Netflix.com with Node.jsNetflix JavaScript Talks - Scaling A/B Testing on Netflix.com with Node.js
Netflix JavaScript Talks - Scaling A/B Testing on Netflix.com with Node.js
 
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
 
HTTP demystified for web developers
HTTP demystified for web developersHTTP demystified for web developers
HTTP demystified for web developers
 
Becoming A Php Ninja
Becoming A Php NinjaBecoming A Php Ninja
Becoming A Php Ninja
 
Take control. write a plugin. part II
Take control. write a plugin. part IITake control. write a plugin. part II
Take control. write a plugin. part II
 
PHP 4? OMG! A small vademecum for obsolete software migration.
PHP 4? OMG! A small vademecum for obsolete software migration.PHP 4? OMG! A small vademecum for obsolete software migration.
PHP 4? OMG! A small vademecum for obsolete software migration.
 
Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min. Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min.
 
Zero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutesZero to Zend Framework in 10 minutes
Zero to Zend Framework in 10 minutes
 
Hack language
Hack languageHack language
Hack language
 
C# 6
C# 6C# 6
C# 6
 

Andere mochten auch

Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
Roo7break
 
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
 

Andere mochten auch (20)

Powershell training material
Powershell training materialPowershell training material
Powershell training material
 
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!
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
Use Powershell to make your life easy.
Use Powershell to make your life easy.Use Powershell to make your life easy.
Use Powershell to make your life easy.
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
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 ...
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
 
PowerShell Plus v4.7 Overview
PowerShell Plus v4.7 OverviewPowerShell Plus v4.7 Overview
PowerShell Plus v4.7 Overview
 
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
 
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
 
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
 

Ähnlich wie Practical PowerShell Programming for Professional People

Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
Satish Verma
 
resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016
Jason Barr
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
Gabriele Santini
 

Ähnlich wie Practical PowerShell Programming for Professional People (20)

Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
PHP Annotations: They exist! - JetBrains Webinar
 PHP Annotations: They exist! - JetBrains Webinar PHP Annotations: They exist! - JetBrains Webinar
PHP Annotations: They exist! - JetBrains Webinar
 
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
 
Annotations in PHP, They Exist.
Annotations in PHP, They Exist.Annotations in PHP, They Exist.
Annotations in PHP, They Exist.
 
Collaborative Software Development
Collaborative Software DevelopmentCollaborative Software Development
Collaborative Software Development
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Build your own Language - Why and How?
Build your own Language - Why and How?Build your own Language - Why and How?
Build your own Language - Why and How?
 
Govind.ppt.pptx
Govind.ppt.pptxGovind.ppt.pptx
Govind.ppt.pptx
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
Entrepreneur’s guide to programming
Entrepreneur’s guide to programmingEntrepreneur’s guide to programming
Entrepreneur’s guide to programming
 
Python Programming.pptx
Python Programming.pptxPython Programming.pptx
Python Programming.pptx
 
resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
 
Python overview
Python overviewPython overview
Python overview
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
 
How To Be A Better Developer
How To Be A Better DeveloperHow To Be A Better Developer
How To Be A Better Developer
 
Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!Let's contribute, HTML5Rocks/ko!
Let's contribute, HTML5Rocks/ko!
 
Clouds are Not Free: Guide to Observability-Driven Efficiency Optimizations
Clouds are Not Free: Guide to Observability-Driven Efficiency OptimizationsClouds are Not Free: Guide to Observability-Driven Efficiency Optimizations
Clouds are Not Free: Guide to Observability-Driven Efficiency Optimizations
 
Realizzare un Virtual Assistant con Bot Framework Azure e Unity
Realizzare un Virtual Assistant con Bot Framework Azure e UnityRealizzare un Virtual Assistant con Bot Framework Azure e Unity
Realizzare un Virtual Assistant con Bot Framework Azure e Unity
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Practical PowerShell Programming for Professional People

  • 1. Practical PowerShell Programming for Professional People Ben Ten (@Ben0xA) Converge Detroit 2014
  • 2. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) About Me Ben Ten (0xA) @Ben0xA - twitter Chicago - #burbsec Vice President Security Officer Developer PoshSec Framework Developer / Creator Gamer Geek
  • 3. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Overview ● Languages and Development ● PowerShell Scripting ● Resources ● Q&A ● PSA: This is mostly live code scripting in PowerShell. Please code along with me!
  • 4. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Overview Feel free to interrupt and ask questions!
  • 5. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development Before we begin, a bit of a primer! ● Styles of Coding ● Syntax ● Getting Help ● Starting Out
  • 6. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development Styles of Coding/Scripting/Development ● Novice ● Avid Scripter ● Full Time Developer ● Code Monkey
  • 7. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development Styles of Coding/Scripting/Development ● Novice ● Avid Scripter ● Full Time Developer ● Code Monkey
  • 8. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) 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.
  • 9. Practical PowerShell Programming for Professional People Converge Detroit - 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!
  • 10. Practical PowerShell Programming for Professional People Converge Detroit - 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*
  • 11. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development Getting Help! Interactive Help ● ? ● F1 ● Intellisense (Ctrl+Space) ● Get-Help
  • 12. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development Getting Help! Search Engines FTW! Google is not the end all in searches. For Development I prefer DuckDuckGo! https://duckduckgo.com
  • 13. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Languages and Development
  • 14. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 15. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) PowerShell Overview PowerShell was designed by : ● Jeffrey Snover (@jsnover) ● Bruce Payette (@BrucePayette) ● James Truher Initial release was November 14, 2006
  • 16. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 17. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) PowerShell 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)
  • 18. Practical PowerShell Programming for Professional People Converge Detroit - 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
  • 19. Practical PowerShell Programming for Professional People Converge Detroit - 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
  • 20. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 21. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 22. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 23. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 24. Practical PowerShell Programming for Professional People Converge Detroit - 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
  • 25. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) PowerShell
  • 26. Practical PowerShell Programming for Professional People Converge Detroit - 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!
  • 27. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 28. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 29. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 30. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1 Variable(s): a symbolic name associated with a value and whose associated value may be changed.
  • 31. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1 Hard-Coded: Typing the value directly into your script. Our “Hello World” text was hard-coded.
  • 32. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 33. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1 PowerShell Variables: Let's rewrite our HelloWorld.ps1 to use a variable $message with our text “Hello World”.
  • 34. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 35. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 36. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 37. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 38. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 39. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 40. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 41. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 42. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 43. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 44. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 45. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 46. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 47. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) HelloWorld.ps1
  • 48. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Getting Input Write-Output is great. But how do you get information from a user? Read-Host
  • 49. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Getting Input
  • 50. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Getting Input
  • 51. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 52. Practical PowerShell Programming for Professional People Converge Detroit - 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!!!!
  • 53. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 54. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic A Conditional Operator: -and = both conditions must be true. -or = only one of the conditions must be true.
  • 55. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic A Conditional Operator: -eq = Equals -lt = Less Than -gt = Greater Than -ne = Not Equal -ge = Great Than or Equal -le = Less Than or Equal
  • 56. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic A Conditional Operator: -Like -NotLike -Match -NotMatch -Contains -NotContains -In -NotIn -Replace
  • 57. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 58. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 59. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 60. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 61. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 62. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 63. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 64. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Conditional Logic
  • 65. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Parameters A Parameter is: A variable that allows you to pass an object to a Cmdlet, Function, or Script. Get-ChildItem
  • 66. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Parameters
  • 67. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Parameters 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>]
  • 68. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Parameters
  • 69. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Parameters
  • 70. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 71. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Objects vs Text
  • 72. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Piping Piping is: a way of moving something, unchanged, from one place to another.
  • 73. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 74. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Piping
  • 75. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Piping
  • 76. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 77. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Loops Loops: ● ForEach ● ForEach-Object ● For ● While ● Do While ● Do Until
  • 78. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Loops
  • 79. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Loops
  • 80. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Loops
  • 81. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Comments Comments are defined by the # symbol. Block comments are enclosed with <# and #>. .SYNOPSIS .DESCRIPTION .PARAMETER .EXAMPLE
  • 82. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Comments
  • 83. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Putting it all Together The final program! Requirements: ● Search all files. ● Find the ones that were modified in a specific date range. ● Create a list of those files and display them.
  • 84. Practical PowerShell Programming for Professional People Converge Detroit - 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.
  • 85. Practical PowerShell Programming for Professional People Converge Detroit - 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!
  • 86. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Resources Freenode (irc.freenode.net) #PowerShell, #pssec, #poshsec channels. Learn Windows PowerShell in a Month of Lunches ~ Don Jones Carlos Perez – PowerShell Workshop at DerbyCon.
  • 87. Practical PowerShell Programming for Professional People Converge Detroit - 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 QUESTIONS?!
  • 88. Practical PowerShell Programming for Professional People Converge Detroit - Ben Ten (@Ben0xA) Thank You!