SlideShare a Scribd company logo
PowerShell Fundamentals
BY PAWEL MOZDZEN
1
PowerShell ISE
POWERSHELL FUNDAMENTALS 2
DEMOFinalProduct.ps1
FinalProductRun.ps1
What we will cover
POWERSHELL FUNDAMENTALS 3
 Custom Objects
 Advanced Parameters
 Steps for Building a Proper Function
 Help System
 Pipeline
 Scope
But not..
 PowerShell Syntax
 Specific SharePoint Cmdlets
Help System
 Update-Help
 Get-Help
 Get-Help Parameters
- Full
- Examples
- Detailed
- Online
- ShowWindow
 Get-Member
POWERSHELL FUNDAMENTALS 4
Examples
1. Get-Help Get-SPSite –Full
2. Get-Help Get-SP*
3. Get-Help Get-SPSite –Parameter Limit
Examples
1. Get-SPSite | Get-Member
2. Get-SPSite | Select Url, Owner | Get-Member
PowerShell ISE
POWERSHELL FUNDAMENTALS 5
DEMOHelp.ps1
Understanding Help Syntax
Get-Help New-SPSite
Syntax
New-SPSite [-AdministrationSiteType
<None | TenantAdministration>] [-AssignmentCollection <SPAssignmentCollection>] [-
CompatibilityLevel <Int32>] [-Confirm <SwitchParameter>] [-ContentDatabase
<SPContentDatabasePipeBind>] [-Description <String>] [-HostHeaderWebApplication
<SPWebApplicationPipeBind>] [-Language <UInt32>] [-Name <String>] [-
OverrideCompatibilityRestriction <SwitchParameter>] [-OwnerEmail <String>] [-QuotaTemplate
<SPQuotaTemplatePipeBind>] [-SecondaryEmail <String>] [-SecondaryOwnerAlias
<SPUserPipeBind>] [-SiteSubscription <SPSiteSubscriptionPipeBind>] [-Template
<SPWebTemplatePipeBind>] [-WhatIf <SwitchParameter>]
POWERSHELL FUNDAMENTALS 6
[-Url] <String>[-Url] <String> -OwnerAlias <SPUserPipeBind>-OwnerAlias <SPUserPipeBind>
[<CommonParameters>][<CommonParameters>]
Get-Help New-SPUser …[-PermissionLevel <String[]>] …..
Pipeline
POWERSHELL FUNDAMENTALS 7
Pipeline - the Old Way
POWERSHELL FUNDAMENTALS 8
Command I
StdOut StdIn StdErr
Command II
StdOut StdIn StdErr
Text
Working with Pipeline – PowerShell Way
POWERSHELL FUNDAMENTALS 9
Command I
Output Errors Warnings
Command II
-Param
OBJECT
Verbose Debug
-Param-Param
1
-Param
-Param-Param
…n
?  Pipeline Parameter Binding
 By Value
 By Property Name
Pipeline
POWERSHELL FUNDAMENTALS 10
DEMOPipeByValue.ps1
PipeByPropertyName.ps1
Scope
Global Scope - Runspace
POWERSHELL FUNDAMENTALS 11
Global Scope - Runspace
Function
Scope
Script Scope
Function
Scope
Script Scope
Script Scope
Function Scope
Compartmentalization of Scope
 General Rules
 Scoped elements exist only in scope they were created.
 Accessing non-existent element will result in reaching out to the parent scope.
 Scoped elements can be created with the same name as in the parent scope.
 When a scope is finished processing it is destroyed and removed from memory.
 Dot Sourcing
 Private variables
 Strict Mode
 Set-StrictMode -Off
 Set-StrictMode -Version [1,2,3,latest]
Scope
POWERSHELL FUNDAMENTALS 12
Scope
POWERSHELL FUNDAMENTALS 13
DEMOScopeRunScript.ps1
ScopeTempScript.ps1
 Benefits for turning script into a function
 Once loaded into memory it is available for later use: Dot-Sourcing, Import-Module
 Function has its own scope
 Multiple functions per script file.
 Provides better separation of concerns for complex tasks.
 Function Example
function Get-SiteColumnStats{
$spWeb = Get-spweb "http://sps-demo:5555/sites/acct"
$spFields = $spWeb.Fields
$spFields | Group-Object TypeAsString | Sort-Object Count -Descending
}
Get-SiteColumnStats
Functions
POWERSHELL FUNDAMENTALS 14
 Everything in PowerShell is an OBJECT
 Functions and scripts can return only one kind of thing.
 Use Custom Objects to consolidate information before returning it.
 To return a collection of data assign it to a property of the custom object.
 Techniques for creating custom objects:
 Using Hashtable
 Using Select-Object
 Using Add-Member
 Using Type Declaration
Custom Objects
POWERSHELL FUNDAMENTALS 15
Custom Objects – Creation Techniques
POWERSHELL FUNDAMENTALS 16
DEMOCustomObjects.ps1
Custom Objects - Real Life Example
POWERSHELL FUNDAMENTALS 17
DEMOExport-Audiences.ps1
Functions – Advanced Parameters
POWERSHELL FUNDAMENTALS 18
 Get-Help about_Functions_Advanced_Paramenters
 All PowerShell functions follow a verb dash
noun naming standard.
 Adds certain features to a function:
• Enables [Parameter()] decorator,
• Adds standard set of extra function
parameters such us –verbose, -debug
 Makes parameter required.
 Any default values will be ignored.
 Enables to accept values from pipeline.
 Accepts values of the same type.
 Only one such decorator for the same type.
 Enables to accept values from pipeline.
 Accepts values from passed in object’s
properties same name.
 First it will try to find a match By Value then
by Property Name
 BEGIN and END blocks execute only once.
 PROCESS block executes for each piped in
object
 Important to handle function calls where
values are passed in via parameter.
 Redundant if piped in.
Advanced Parameters - Real Life Example
POWERSHELL FUNDAMENTALS 19
DEMOExport-Audiences.ps1
 Defined as set of parameter decorators.
 Each validator defined as a separate decorator.
[ValidateCount(1,50)]
[ValidateLength(1,50)]
[ValidateScript({...})]
[ValidateSet[("One","Two","Three")]
[ValidatePattern("w+w+")]
[ValidateRange(1,5)]
Parameter Validation
POWERSHELL FUNDAMENTALS 20
 Validate against null or empty values:
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
 For mandatory parameters to allow null values:
[AllowNull()]
[AllowEmptyString()]
[AllowEmptyCollection()]
Parameter Validation – Cont’d.
POWERSHELL FUNDAMENTALS 21
Parameter Validation - Example
POWERSHELL FUNDAMENTALS 22
 Verbose Output: Write-Verbose
A way to check variables’ state in longer scripts
A way to comment script behavior documenting it
A way to notify about longer running processes
And the most important..
 Debug Output: Write-Debug
To let you know which line is currently processing
To pause the execution and let user check things
Verbose and Debug Output
POWERSHELL FUNDAMENTALS 23
a way to avoid using Write-Host
 Converting script to a module
 Accessing Module
 Use: Import-Module moduleFileName.psm1
 Place module in PowerShell searchable locations: $env:PSModulePath
Special considerations for saving modules in PowerShell locations:
 Always save your module within a folder of the same name.
 Use letters and numbers only.
 Exporting Module Members
Export-ModuleMember -Function <functionName>
Export-ModuleMember -Variable <variableName>
Example: Export-ModuleMember -Function *-*
Functions in Script Modules
POWERSHELL FUNDAMENTALS 24
 Start with defining a task.
 Build base command(s).
 Turn it into a function.
 Parameterize it.
 Test it calling in different ways.
 Add error handling if necessary.
 Add Verbose and Debug output.
 Turn it into a module.
Steps for Building a Proper Function
POWERSHELL FUNDAMENTALS 25
Steps for Building a Proper Function
POWERSHELL FUNDAMENTALS 26
DEMOFunctionBuildingSteps.ps1
PowerShell Fundamentals
QUESTIONS
27

More Related Content

What's hot

Angular 2 introduction
Angular 2 introductionAngular 2 introduction
Angular 2 introduction
Christoffer Noring
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
Alex Eftimie
 
Writing Ansible Modules (CLT'19)
Writing Ansible Modules (CLT'19)Writing Ansible Modules (CLT'19)
Writing Ansible Modules (CLT'19)
Martin Schütte
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
Jiayun Zhou
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
XML-Motor
XML-MotorXML-Motor
XML-Motor
Abhishek Kumar
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Knoldus Inc.
 
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Adin Ermie
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo
Evans Hauser
 
BeScala - Scala Guice
BeScala -  Scala GuiceBeScala -  Scala Guice
BeScala - Scala Guice
BeScala
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Adin Ermie
 
Manage Add-on Services in Apache Ambari
Manage Add-on Services in Apache AmbariManage Add-on Services in Apache Ambari
Manage Add-on Services in Apache Ambari
Jayush Luniya
 
Ansible
AnsibleAnsible
Ansible
Rahul Bajaj
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
guest8cd374
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Salaudeen Rajack
 
Immutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and TerraformImmutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and Terraform
Michael Peacock
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
Michal Bigos
 

What's hot (20)

Angular 2 introduction
Angular 2 introductionAngular 2 introduction
Angular 2 introduction
 
Django Celery - A distributed task queue
Django Celery - A distributed task queueDjango Celery - A distributed task queue
Django Celery - A distributed task queue
 
Writing Ansible Modules (CLT'19)
Writing Ansible Modules (CLT'19)Writing Ansible Modules (CLT'19)
Writing Ansible Modules (CLT'19)
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
XML-Motor
XML-MotorXML-Motor
XML-Motor
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional Statements
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo
 
BeScala - Scala Guice
BeScala -  Scala GuiceBeScala -  Scala Guice
BeScala - Scala Guice
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
 
Manage Add-on Services in Apache Ambari
Manage Add-on Services in Apache AmbariManage Add-on Services in Apache Ambari
Manage Add-on Services in Apache Ambari
 
Ansible
AnsibleAnsible
Ansible
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Immutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and TerraformImmutable Infrastructure with Packer Ansible and Terraform
Immutable Infrastructure with Packer Ansible and Terraform
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 

Similar to PowerShell Fundamentals

Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009rsnarayanan
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!
walk2talk srl
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
Hitesh Mohapatra
 
PowerShell for SharePoint Admins
PowerShell for SharePoint AdminsPowerShell for SharePoint Admins
PowerShell for SharePoint AdminsRick Taylor
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
Salaudeen Rajack
 
Power shell for sp admins
Power shell for sp adminsPower shell for sp admins
Power shell for sp adminsRick Taylor
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShell
Phan Hien
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
Bryan Cafferky
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
Boulos Dib
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Boulos Dib
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Tech OneStop
 
Intro to PowerShell Workflow
Intro to PowerShell WorkflowIntro to PowerShell Workflow
Intro to PowerShell Workflow
Jeffery Hicks
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
Binh Nguyen
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellSharePoint Saturday NY
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellSharePoint Saturday NY
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
Michelangelo van Dam
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
Rodolfo Carvalho
 

Similar to PowerShell Fundamentals (20)

Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
 
PowerShell for SharePoint Admins
PowerShell for SharePoint AdminsPowerShell for SharePoint Admins
PowerShell for SharePoint Admins
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
 
Power shell for sp admins
Power shell for sp adminsPower shell for sp admins
Power shell for sp admins
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShell
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter Value
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
 
Intro to PowerShell Workflow
Intro to PowerShell WorkflowIntro to PowerShell Workflow
Intro to PowerShell Workflow
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 

Recently uploaded

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

PowerShell Fundamentals

  • 2. PowerShell ISE POWERSHELL FUNDAMENTALS 2 DEMOFinalProduct.ps1 FinalProductRun.ps1
  • 3. What we will cover POWERSHELL FUNDAMENTALS 3  Custom Objects  Advanced Parameters  Steps for Building a Proper Function  Help System  Pipeline  Scope But not..  PowerShell Syntax  Specific SharePoint Cmdlets
  • 4. Help System  Update-Help  Get-Help  Get-Help Parameters - Full - Examples - Detailed - Online - ShowWindow  Get-Member POWERSHELL FUNDAMENTALS 4 Examples 1. Get-Help Get-SPSite –Full 2. Get-Help Get-SP* 3. Get-Help Get-SPSite –Parameter Limit Examples 1. Get-SPSite | Get-Member 2. Get-SPSite | Select Url, Owner | Get-Member
  • 6. Understanding Help Syntax Get-Help New-SPSite Syntax New-SPSite [-AdministrationSiteType <None | TenantAdministration>] [-AssignmentCollection <SPAssignmentCollection>] [- CompatibilityLevel <Int32>] [-Confirm <SwitchParameter>] [-ContentDatabase <SPContentDatabasePipeBind>] [-Description <String>] [-HostHeaderWebApplication <SPWebApplicationPipeBind>] [-Language <UInt32>] [-Name <String>] [- OverrideCompatibilityRestriction <SwitchParameter>] [-OwnerEmail <String>] [-QuotaTemplate <SPQuotaTemplatePipeBind>] [-SecondaryEmail <String>] [-SecondaryOwnerAlias <SPUserPipeBind>] [-SiteSubscription <SPSiteSubscriptionPipeBind>] [-Template <SPWebTemplatePipeBind>] [-WhatIf <SwitchParameter>] POWERSHELL FUNDAMENTALS 6 [-Url] <String>[-Url] <String> -OwnerAlias <SPUserPipeBind>-OwnerAlias <SPUserPipeBind> [<CommonParameters>][<CommonParameters>] Get-Help New-SPUser …[-PermissionLevel <String[]>] …..
  • 8. Pipeline - the Old Way POWERSHELL FUNDAMENTALS 8 Command I StdOut StdIn StdErr Command II StdOut StdIn StdErr Text
  • 9. Working with Pipeline – PowerShell Way POWERSHELL FUNDAMENTALS 9 Command I Output Errors Warnings Command II -Param OBJECT Verbose Debug -Param-Param 1 -Param -Param-Param …n ?  Pipeline Parameter Binding  By Value  By Property Name
  • 11. Scope Global Scope - Runspace POWERSHELL FUNDAMENTALS 11 Global Scope - Runspace Function Scope Script Scope Function Scope Script Scope Script Scope Function Scope Compartmentalization of Scope
  • 12.  General Rules  Scoped elements exist only in scope they were created.  Accessing non-existent element will result in reaching out to the parent scope.  Scoped elements can be created with the same name as in the parent scope.  When a scope is finished processing it is destroyed and removed from memory.  Dot Sourcing  Private variables  Strict Mode  Set-StrictMode -Off  Set-StrictMode -Version [1,2,3,latest] Scope POWERSHELL FUNDAMENTALS 12
  • 14.  Benefits for turning script into a function  Once loaded into memory it is available for later use: Dot-Sourcing, Import-Module  Function has its own scope  Multiple functions per script file.  Provides better separation of concerns for complex tasks.  Function Example function Get-SiteColumnStats{ $spWeb = Get-spweb "http://sps-demo:5555/sites/acct" $spFields = $spWeb.Fields $spFields | Group-Object TypeAsString | Sort-Object Count -Descending } Get-SiteColumnStats Functions POWERSHELL FUNDAMENTALS 14
  • 15.  Everything in PowerShell is an OBJECT  Functions and scripts can return only one kind of thing.  Use Custom Objects to consolidate information before returning it.  To return a collection of data assign it to a property of the custom object.  Techniques for creating custom objects:  Using Hashtable  Using Select-Object  Using Add-Member  Using Type Declaration Custom Objects POWERSHELL FUNDAMENTALS 15
  • 16. Custom Objects – Creation Techniques POWERSHELL FUNDAMENTALS 16 DEMOCustomObjects.ps1
  • 17. Custom Objects - Real Life Example POWERSHELL FUNDAMENTALS 17 DEMOExport-Audiences.ps1
  • 18. Functions – Advanced Parameters POWERSHELL FUNDAMENTALS 18  Get-Help about_Functions_Advanced_Paramenters  All PowerShell functions follow a verb dash noun naming standard.  Adds certain features to a function: • Enables [Parameter()] decorator, • Adds standard set of extra function parameters such us –verbose, -debug  Makes parameter required.  Any default values will be ignored.  Enables to accept values from pipeline.  Accepts values of the same type.  Only one such decorator for the same type.  Enables to accept values from pipeline.  Accepts values from passed in object’s properties same name.  First it will try to find a match By Value then by Property Name  BEGIN and END blocks execute only once.  PROCESS block executes for each piped in object  Important to handle function calls where values are passed in via parameter.  Redundant if piped in.
  • 19. Advanced Parameters - Real Life Example POWERSHELL FUNDAMENTALS 19 DEMOExport-Audiences.ps1
  • 20.  Defined as set of parameter decorators.  Each validator defined as a separate decorator. [ValidateCount(1,50)] [ValidateLength(1,50)] [ValidateScript({...})] [ValidateSet[("One","Two","Three")] [ValidatePattern("w+w+")] [ValidateRange(1,5)] Parameter Validation POWERSHELL FUNDAMENTALS 20
  • 21.  Validate against null or empty values: [ValidateNotNull()] [ValidateNotNullOrEmpty()]  For mandatory parameters to allow null values: [AllowNull()] [AllowEmptyString()] [AllowEmptyCollection()] Parameter Validation – Cont’d. POWERSHELL FUNDAMENTALS 21
  • 22. Parameter Validation - Example POWERSHELL FUNDAMENTALS 22
  • 23.  Verbose Output: Write-Verbose A way to check variables’ state in longer scripts A way to comment script behavior documenting it A way to notify about longer running processes And the most important..  Debug Output: Write-Debug To let you know which line is currently processing To pause the execution and let user check things Verbose and Debug Output POWERSHELL FUNDAMENTALS 23 a way to avoid using Write-Host
  • 24.  Converting script to a module  Accessing Module  Use: Import-Module moduleFileName.psm1  Place module in PowerShell searchable locations: $env:PSModulePath Special considerations for saving modules in PowerShell locations:  Always save your module within a folder of the same name.  Use letters and numbers only.  Exporting Module Members Export-ModuleMember -Function <functionName> Export-ModuleMember -Variable <variableName> Example: Export-ModuleMember -Function *-* Functions in Script Modules POWERSHELL FUNDAMENTALS 24
  • 25.  Start with defining a task.  Build base command(s).  Turn it into a function.  Parameterize it.  Test it calling in different ways.  Add error handling if necessary.  Add Verbose and Debug output.  Turn it into a module. Steps for Building a Proper Function POWERSHELL FUNDAMENTALS 25
  • 26. Steps for Building a Proper Function POWERSHELL FUNDAMENTALS 26 DEMOFunctionBuildingSteps.ps1