SlideShare a Scribd company logo
Scripting as a
Second Language
Basic PowerShell Toolmaking
Rob Dunn - @maximillianx
• Lead Systems Administrator
• IT Pro for 22 years
• In the Spiceworks Community since 2007
• Pure Capsaicin since 2014
Sponsored by Netwrix – www.netwrix.com
Free products:
• Change Notifier for AD, File Servers, Group Policy
• Account Lockout Examiner Tool
• Password Expiration Notifier
• Effective Permissions Analyzer
• And more!
Flagship Product:
• Audit (Active Directory, Azure AD, Oracle, SharePoint, VMware, O365, and more)
#SPICEWORLD2016
• My take on the Difference Between a Script and a Tool
• Toolmaking with a Tool (not just me), the ISE
• The Genesis of the Tool
• Demo!
What We’ll Cover
#SPICEWORLD2016
A simple script is a file containing a series of runtime
instructions which can be executed repeatedly with a
relatively specific focus which produces an expected
outcome.
Typically, the user running the script doesn’t have much, if
any control over the output.
What is a Simple Script?
#SPICEWORLD2016
• Input
• Functional
• Output
What is a Tool – Three Types
#SPICEWORLD2016
What do We Use to Make Our PowerShell Scripts
and Tools? [Demo]
Use the right tool for the job!
• Not NotePad or other text-based
editors
• Something that is “PowerShell”
aware
• This could be Visual Studio,
VSCode, Sapien PowerShell Studio,
or…the FREE Microsoft ISE.
Advantages?
1. Easily execute single lines or
sections of code
2. Tab completion of parameters,
properties & methods
3. Debugging, error discovery, and
syntax highlighting
4. Add-on support
#SPICEWORLD2016
Toolmaking: My Thought Process
Problem
Level of
Need
Output Input
#SPICEWORLD2016
Start with a bit of code that you’ve used once or twice and build your script
around that.
Today’s Method: Build From the “Inside Out”
 Get-Command - Find that cmdlet you’re looking for
 Get-Help (RTFM, right?! Don’t forget to ‘Update-
Help’ as well!)
 Get-Member - Find out the methods and properties
associated with an object*
* Pretty much everything in PowerShell is an object
Quick review: Cmdlets you must know
Quick review: What is a PowerShell Object?
It’s a “thing” that represents
something.
You can also think of it like
a row in a database table -
with a twist
Properties
• $Friend.FirstName = Scott
• $Friend.LastName = Brosnan
• $Friend.Height = 1.7272
• $Friend.Funny = $True
• $Friend.BurnsUnderAStreetL
ampBecauseHeMustBeAVam
pireNotATwilightVampireThe
OtherKind= $True
$Chair
$Friend = Get-Friend | Where-Object FirstName –eq “Scott”
$Friend.BeatBox(20)
$Friend
Methods
• $Friend.Complain
• $Friend.TellHorribleJoke
• $Friend.TakeDownStorage
Array
• $Friend.BeatBox
Quick review: What is a PowerShell Object?
It’s a “thing” that represents
something.
You can also think of it like
a row in a database table -
with a twist
$Chair
$Friend = Get-Friend | Where-Object FirstName –eq “Scott”
$Friend.BeatBox(20)
$Friend
Get Event Log Entries surrounding an item of interest
The Scenario
#SPICEWORLD2016
#SPICEWORLD2016
The Problem
A service account is experiencing a lockout in the middle of the night.
IT needs to gather all the event log entries from the system log x minutes
before and x minutes after the time of a specified event to see if there is
“something else” going on.
#SPICEWORLD2016
The IT manager has determined this problem occurs enough times to warrant a
closer look at the symptoms by his junior staff; preferably by utilizing a
consistent method when the problem recurs.
The Level Of Need
#SPICEWORLD2016
The IT manager would like to have all the surrounding event log entries in a
view which can be browsed or exported to CSV for further analysis; potentially
in Excel so they can compare them.
The Output
#SPICEWORLD2016
1. The date and time of Event we’re interested in
2. The range of minutes before and after the event to gather other possible
interesting information.
The Input (our Parameters)
#SPICEWORLD2016
…find system event log items x minutes before and x
minutes after event of interest occurs
…output events to end user as objects
BONUS:
Can we get these items from ALL event logs?
To use these parameters, our script needs to:
Let’s Code!
#SPICEWORLD2016
#SPICEWORLD2016
• Comment-Based Help
• Format your script – look like a Pro!
• Make your scripts and functions single purpose, name them accordingly
• Use Microsoft supported verbs to name your functions and scripts (Get-
Verb)
• Configure Execution Policy to run PS1 files (Set-ExecutionPolicy –
ExecutionPolicy RemoteSigned, etc.)
Best Practices
#SPICEWORLD2016
1. Save your file as a .PS1 and share with your co-workers
2. Create a module (easier than it sounds)
Share and Enjoy! I.e. Extra Credit 
#SPICEWORLD2016
[Book] PowerShell in a Month of Lunches, Don Jones &
Jeffery Hicks
[Book] PowerShell ToolMaking in a Month of Lunches, Don
Jones & Jeffery Hicks
[Web] PowerShell 3.0 JumpStart, Microsoft Virtual
Academy, Jason Helmick, Jeffery Snover*
*heck, anything by Jeffery Snover, I mean, he invented it!
Learning PowerShell?
Thank you!

More Related Content

PDF
Getting Started with Rails
PPTX
SQL Provider
KEY
WordPress APIs
KEY
Custom Post Types in Depth at WordCamp Montreal
PDF
Solr: 4 big features
PDF
Scot Hacker: Building a Killer Bucketlist Site with Python/Django
PDF
Becoming a better WordPress Developer
PDF
Building a spa_in_30min
Getting Started with Rails
SQL Provider
WordPress APIs
Custom Post Types in Depth at WordCamp Montreal
Solr: 4 big features
Scot Hacker: Building a Killer Bucketlist Site with Python/Django
Becoming a better WordPress Developer
Building a spa_in_30min

What's hot (12)

KEY
State-of-the-Art Drupal Search with Apache Solr
PDF
Cain & Obenland — Episode 4
PDF
Theming in WordPress - Where do I Start?
PPTX
Building Social Tools
PDF
Drupal security
PDF
Elastic Search
PDF
How to start developing apps for Firefox OS
PDF
How Solr Search Works
PPTX
Open Source Search FTW
PPT
On-page SEO for Drupal
PDF
Etsy Search: How We Index and Query 26 Million One-of-a-kind Items
State-of-the-Art Drupal Search with Apache Solr
Cain & Obenland — Episode 4
Theming in WordPress - Where do I Start?
Building Social Tools
Drupal security
Elastic Search
How to start developing apps for Firefox OS
How Solr Search Works
Open Source Search FTW
On-page SEO for Drupal
Etsy Search: How We Index and Query 26 Million One-of-a-kind Items
Ad

Viewers also liked (20)

PPTX
Implementing dr w. hyper v clustering
PPTX
Combining output from multiple sources
PPT
PowerShell Functions
PPTX
PowerShell crashcourse for sharepoint
PPT
Managing SQLserver
PPT
Automating Active Directory mgmt in PowerShell
PPT
PowerShell v4 Desired State Configuration
PPTX
Introduction to powershell
PPT
PS scripting and modularization
PPTX
Three cool cmdlets I wish PowerShell Had!
PDF
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
PPT
PowerShell 8tips
PPTX
PowerShell crash course
PPTX
Best free tools for w d a
PPTX
PowerShell and WMI
PPTX
Best free tools for win database admin
PPT
PowerShell crashcourse
PPTX
Meet Windows PowerShell
PPT
From VB Script to PowerShell
PPT
PS error handling and debugging
Implementing dr w. hyper v clustering
Combining output from multiple sources
PowerShell Functions
PowerShell crashcourse for sharepoint
Managing SQLserver
Automating Active Directory mgmt in PowerShell
PowerShell v4 Desired State Configuration
Introduction to powershell
PS scripting and modularization
Three cool cmdlets I wish PowerShell Had!
Advanced Tools & Scripting with PowerShell 3.0 Jump Start - Certificate
PowerShell 8tips
PowerShell crash course
Best free tools for w d a
PowerShell and WMI
Best free tools for win database admin
PowerShell crashcourse
Meet Windows PowerShell
From VB Script to PowerShell
PS error handling and debugging
Ad

Similar to Basic PowerShell Toolmaking - Spiceworld 2016 session (20)

PPTX
Managing SharePoint Anywhere with Windows PowerShell
PDF
F8 tech talk_pinterest_v4
PPTX
Holy PowerShell, BATman! - dogfood edition
PDF
My tryst with sourcecode review
PPTX
PowerShell - Be A Cool Blue Kid
PDF
Build a game with javascript (april 2017)
PDF
If you want to automate, you learn to code
PDF
Kiran karnad rtc2014 ghdb-final
PPTX
Design for scale
PPTX
Maintainable Machine Learning Products
PDF
Build a game with javascript (may 21 atlanta)
PPTX
System insight without Interference
PPTX
My first powershell script
PDF
MongoDB Revised Sharding Guidelines MongoDB 3.x_Kimberly_Wilkins
PDF
Ranger BSides-FINAL
PDF
Building APIs in an easy way using API Platform
PDF
Under the Wire PowerShell workshop - BSides Augusta 2018
PDF
Weaponizing Recon - Smashing Applications for Security Vulnerabilities & Profits
PPTX
Intro to SharePoint + PowerShell
PDF
Add-On Development: EE Expects that Every Developer will do his Duty
Managing SharePoint Anywhere with Windows PowerShell
F8 tech talk_pinterest_v4
Holy PowerShell, BATman! - dogfood edition
My tryst with sourcecode review
PowerShell - Be A Cool Blue Kid
Build a game with javascript (april 2017)
If you want to automate, you learn to code
Kiran karnad rtc2014 ghdb-final
Design for scale
Maintainable Machine Learning Products
Build a game with javascript (may 21 atlanta)
System insight without Interference
My first powershell script
MongoDB Revised Sharding Guidelines MongoDB 3.x_Kimberly_Wilkins
Ranger BSides-FINAL
Building APIs in an easy way using API Platform
Under the Wire PowerShell workshop - BSides Augusta 2018
Weaponizing Recon - Smashing Applications for Security Vulnerabilities & Profits
Intro to SharePoint + PowerShell
Add-On Development: EE Expects that Every Developer will do his Duty

Recently uploaded (20)

PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
A Presentation on Touch Screen Technology
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Hybrid model detection and classification of lung cancer
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
cloud_computing_Infrastucture_as_cloud_p
A novel scalable deep ensemble learning framework for big data classification...
1 - Historical Antecedents, Social Consideration.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Enhancing emotion recognition model for a student engagement use case through...
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Group 1 Presentation -Planning and Decision Making .pptx
A Presentation on Touch Screen Technology
SOPHOS-XG Firewall Administrator PPT.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Hybrid model detection and classification of lung cancer
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Zenith AI: Advanced Artificial Intelligence
WOOl fibre morphology and structure.pdf for textiles
Encapsulation_ Review paper, used for researhc scholars
cloud_computing_Infrastucture_as_cloud_p

Basic PowerShell Toolmaking - Spiceworld 2016 session

  • 1. Scripting as a Second Language Basic PowerShell Toolmaking
  • 2. Rob Dunn - @maximillianx • Lead Systems Administrator • IT Pro for 22 years • In the Spiceworks Community since 2007 • Pure Capsaicin since 2014
  • 3. Sponsored by Netwrix – www.netwrix.com Free products: • Change Notifier for AD, File Servers, Group Policy • Account Lockout Examiner Tool • Password Expiration Notifier • Effective Permissions Analyzer • And more! Flagship Product: • Audit (Active Directory, Azure AD, Oracle, SharePoint, VMware, O365, and more)
  • 4. #SPICEWORLD2016 • My take on the Difference Between a Script and a Tool • Toolmaking with a Tool (not just me), the ISE • The Genesis of the Tool • Demo! What We’ll Cover
  • 5. #SPICEWORLD2016 A simple script is a file containing a series of runtime instructions which can be executed repeatedly with a relatively specific focus which produces an expected outcome. Typically, the user running the script doesn’t have much, if any control over the output. What is a Simple Script?
  • 6. #SPICEWORLD2016 • Input • Functional • Output What is a Tool – Three Types
  • 7. #SPICEWORLD2016 What do We Use to Make Our PowerShell Scripts and Tools? [Demo] Use the right tool for the job! • Not NotePad or other text-based editors • Something that is “PowerShell” aware • This could be Visual Studio, VSCode, Sapien PowerShell Studio, or…the FREE Microsoft ISE. Advantages? 1. Easily execute single lines or sections of code 2. Tab completion of parameters, properties & methods 3. Debugging, error discovery, and syntax highlighting 4. Add-on support
  • 8. #SPICEWORLD2016 Toolmaking: My Thought Process Problem Level of Need Output Input
  • 9. #SPICEWORLD2016 Start with a bit of code that you’ve used once or twice and build your script around that. Today’s Method: Build From the “Inside Out”
  • 10.  Get-Command - Find that cmdlet you’re looking for  Get-Help (RTFM, right?! Don’t forget to ‘Update- Help’ as well!)  Get-Member - Find out the methods and properties associated with an object* * Pretty much everything in PowerShell is an object Quick review: Cmdlets you must know
  • 11. Quick review: What is a PowerShell Object? It’s a “thing” that represents something. You can also think of it like a row in a database table - with a twist Properties • $Friend.FirstName = Scott • $Friend.LastName = Brosnan • $Friend.Height = 1.7272 • $Friend.Funny = $True • $Friend.BurnsUnderAStreetL ampBecauseHeMustBeAVam pireNotATwilightVampireThe OtherKind= $True $Chair $Friend = Get-Friend | Where-Object FirstName –eq “Scott” $Friend.BeatBox(20) $Friend
  • 12. Methods • $Friend.Complain • $Friend.TellHorribleJoke • $Friend.TakeDownStorage Array • $Friend.BeatBox Quick review: What is a PowerShell Object? It’s a “thing” that represents something. You can also think of it like a row in a database table - with a twist $Chair $Friend = Get-Friend | Where-Object FirstName –eq “Scott” $Friend.BeatBox(20) $Friend
  • 13. Get Event Log Entries surrounding an item of interest The Scenario #SPICEWORLD2016
  • 14. #SPICEWORLD2016 The Problem A service account is experiencing a lockout in the middle of the night. IT needs to gather all the event log entries from the system log x minutes before and x minutes after the time of a specified event to see if there is “something else” going on.
  • 15. #SPICEWORLD2016 The IT manager has determined this problem occurs enough times to warrant a closer look at the symptoms by his junior staff; preferably by utilizing a consistent method when the problem recurs. The Level Of Need
  • 16. #SPICEWORLD2016 The IT manager would like to have all the surrounding event log entries in a view which can be browsed or exported to CSV for further analysis; potentially in Excel so they can compare them. The Output
  • 17. #SPICEWORLD2016 1. The date and time of Event we’re interested in 2. The range of minutes before and after the event to gather other possible interesting information. The Input (our Parameters)
  • 18. #SPICEWORLD2016 …find system event log items x minutes before and x minutes after event of interest occurs …output events to end user as objects BONUS: Can we get these items from ALL event logs? To use these parameters, our script needs to:
  • 20. #SPICEWORLD2016 • Comment-Based Help • Format your script – look like a Pro! • Make your scripts and functions single purpose, name them accordingly • Use Microsoft supported verbs to name your functions and scripts (Get- Verb) • Configure Execution Policy to run PS1 files (Set-ExecutionPolicy – ExecutionPolicy RemoteSigned, etc.) Best Practices
  • 21. #SPICEWORLD2016 1. Save your file as a .PS1 and share with your co-workers 2. Create a module (easier than it sounds) Share and Enjoy! I.e. Extra Credit 
  • 22. #SPICEWORLD2016 [Book] PowerShell in a Month of Lunches, Don Jones & Jeffery Hicks [Book] PowerShell ToolMaking in a Month of Lunches, Don Jones & Jeffery Hicks [Web] PowerShell 3.0 JumpStart, Microsoft Virtual Academy, Jason Helmick, Jeffery Snover* *heck, anything by Jeffery Snover, I mean, he invented it! Learning PowerShell?

Editor's Notes

  • #9: The Problem: What problem am I trying to solve? The Level of Need: Do I find that I need to solve this problem on more than a handful of occasions? Do I need to delegate this? The Output: What do I want to achieve upon script execution? Do I need to perform an action, review data, or notify someone? The Input: Given the requirements for output, what information do I need to supply to the script in order fulfill the above required output?
  • #11: Get-Command – just like it says, you can use this to “get” any command that Powershell has to offer. You can search based on a word, and wildcards are supported. Get-Command also works for all your Windows console commands, too! Get-Help – again, very descriptive here. You can use Get-Help in conjunction with any other cmdlet to discover what it does and how to use it. Get-Member – this one is different in that you “pipe” other cmdlets into this one to discover what kind of information the cmdlet presents and what kinds of actions you can take on the resultant objects the cmdlet returns. More on objects shortly!