SlideShare uma empresa Scribd logo
1 de 12
SCRIPTING AS A SECOND
LANGUAGE:
INTRODUCTION TO
POWERSHELL
Rob Dunn, System Administrator Lead
“PowerShell is a distributed automation engine
focused on simplifying complex tasks by
composing high level, task-oriented automation
abstractions with an object pipeline and rich
scripting language.”
– Jeffrey Snover
What is PowerShell?
Standardization
Cmdlets
Verb/Noun Get, Set, Add, etc
Objects
Object manipulation is the very foundation of how PowerShell works.
Use Get-Member to find out what an object can do
Pipeline (the ‘|’ symbol)
Take the objects created from one cmdlet and sending it to another
Get-Services
Set-Variable
Add-Content
Get-Service –Name BITS | Stop-Service
The three commands you must know
Get-Command
Get-Help (RTFM, right?!)
How to read help (there’s some key things you need to look for)
Get-Member
Find out the methods and properties associated with an object
 *** Everything in PowerShell is an object ***
#SPICEWORLD2016
Use the right tool for the job!
• Not NotePad or other text-based
editors
• Something that is “PowerShell”
aware
• This could be Visual Studio CE,
VSCode, Sapien PowerShell
Studio, or the built-in Microsoft
ISE.
Advantages?
• Easily execute single lines or
sections of code
• Tab completion of parameters,
properties & methods
• Debugging, error discovery, and
syntax highlighting
• Add-on support
“An object can be
a variable, function, or data
structure. In the object-oriented
programming paradigm, ‘object’
refers to a particular instance of
a class where the object can be a
combination of variables,
functions, and data structures”
-Wikipedia
Object
Properties
Information about this
object
Methods
Things you can do with
this object
?!
Get-Service BITS
or
$Variable = Get-Service BITS
Methods
• $chair.Raise
• $chair.Roll
• $chair.Tilt
• $chair.Break
It’s a “thing” that represents something or many somethings.
Properties
• $chair.ArmWidth = 11.5 cm
• $chair.SeatWidth = 92 cm
• $chair.ArmColor = brown
• $chair.SeatColor = brown
• $chair.WheelCount = 5
$chair
$chair = Get-Chair | Where-Object ArmWidth -eq 11.5cm
$chair.Roll(20ft)
File Discovery Script
Get list of files that haven’t changed for 60 days
Filter files by extension (.log)
List name, path, size and creation date
This exercise will demonstrate how to search for commands, how to utilize the help system,
get-member, and the PowerShell ISE.
Use PS1 extension
Usually best to run from the PowerShell console, ISE, or other PowerShell-integrated
environment
Execution Policy
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
Use Formatting when possible, when you send your scripts to others to peer-review, it
will be easier for them to read (bonus: you won’t get made fun of, well at least for how it
looks)
Don’t use aliases, it will only confuse future you and/or your co-workers
Make your utility-scripts single purpose. Don’t have a SQL DB integrity checker script
also remove databases; that is a special purpose script.
When in need of a pre-written script, check online resources like the Microsoft Script
Gallery.
#Comment your code so future you won’t curse your/their name.
Visit https://goo.gl/Y9RR5z to view a presention by Martin Pugh and myself at
Spiceworld on this topic
At the time, PowerShell 3.0 was current, but the content is still relevant
Skip to 11:50 to view the script writing demo
Remember, there are no
stupid questions. Only
stupid people who ask
questions.
- Confucius
…probably

Mais conteúdo relacionado

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Introduction to PowerShell

  • 1. SCRIPTING AS A SECOND LANGUAGE: INTRODUCTION TO POWERSHELL Rob Dunn, System Administrator Lead
  • 2. “PowerShell is a distributed automation engine focused on simplifying complex tasks by composing high level, task-oriented automation abstractions with an object pipeline and rich scripting language.” – Jeffrey Snover What is PowerShell?
  • 3. Standardization Cmdlets Verb/Noun Get, Set, Add, etc Objects Object manipulation is the very foundation of how PowerShell works. Use Get-Member to find out what an object can do Pipeline (the ‘|’ symbol) Take the objects created from one cmdlet and sending it to another Get-Services Set-Variable Add-Content Get-Service –Name BITS | Stop-Service
  • 4. The three commands you must know Get-Command Get-Help (RTFM, right?!) How to read help (there’s some key things you need to look for) Get-Member Find out the methods and properties associated with an object  *** Everything in PowerShell is an object ***
  • 5. #SPICEWORLD2016 Use the right tool for the job! • Not NotePad or other text-based editors • Something that is “PowerShell” aware • This could be Visual Studio CE, VSCode, Sapien PowerShell Studio, or the built-in Microsoft ISE. Advantages? • Easily execute single lines or sections of code • Tab completion of parameters, properties & methods • Debugging, error discovery, and syntax highlighting • Add-on support
  • 6. “An object can be a variable, function, or data structure. In the object-oriented programming paradigm, ‘object’ refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures” -Wikipedia Object Properties Information about this object Methods Things you can do with this object ?! Get-Service BITS or $Variable = Get-Service BITS
  • 7. Methods • $chair.Raise • $chair.Roll • $chair.Tilt • $chair.Break It’s a “thing” that represents something or many somethings. Properties • $chair.ArmWidth = 11.5 cm • $chair.SeatWidth = 92 cm • $chair.ArmColor = brown • $chair.SeatColor = brown • $chair.WheelCount = 5 $chair $chair = Get-Chair | Where-Object ArmWidth -eq 11.5cm $chair.Roll(20ft)
  • 8. File Discovery Script Get list of files that haven’t changed for 60 days Filter files by extension (.log) List name, path, size and creation date This exercise will demonstrate how to search for commands, how to utilize the help system, get-member, and the PowerShell ISE.
  • 9. Use PS1 extension Usually best to run from the PowerShell console, ISE, or other PowerShell-integrated environment Execution Policy Get-ExecutionPolicy Set-ExecutionPolicy RemoteSigned
  • 10. Use Formatting when possible, when you send your scripts to others to peer-review, it will be easier for them to read (bonus: you won’t get made fun of, well at least for how it looks) Don’t use aliases, it will only confuse future you and/or your co-workers Make your utility-scripts single purpose. Don’t have a SQL DB integrity checker script also remove databases; that is a special purpose script. When in need of a pre-written script, check online resources like the Microsoft Script Gallery. #Comment your code so future you won’t curse your/their name.
  • 11. Visit https://goo.gl/Y9RR5z to view a presention by Martin Pugh and myself at Spiceworld on this topic At the time, PowerShell 3.0 was current, but the content is still relevant Skip to 11:50 to view the script writing demo
  • 12. Remember, there are no stupid questions. Only stupid people who ask questions. - Confucius …probably

Notas do Editor

  1. Powershell is a tool - it can be a simple tool.  What is it to us as IT professionals?