SlideShare a Scribd company logo
Intro to
PowerShell
Workflow
JEFF HICKS
Agenda
What is Workflow?
Workflow Syntax
Running Workflows
Practical Workflows
Best Practices
Think!
Just because you can use a PowerShell
workflow doesn’t mean you should.
Definitions – What is a
Workflow
A robust multi-machine orchestration
engine
Designed for long running unattended tasks
across potentially thousands of machines
Persistent states can survive reboots and
network interruptions
Previously built in Visual Studio
Definitions - What is
PowerShell Workflow?
• Persistence via check points
• Suspend and Resume capabilitiesRobust
• Parallel tasks
• Connection pooling
• Connection throttling
Performance
and
Scalability
• Use existing cmdlets*
• No need to master XAML or use Visual Studio
• Built in parameters for multi-machine management
PowerShell
Based
Workflow Scenarios
Server deployment
Server configuration/remediation
User provisioning
Private cloud deployments
Sharepoint configuration
Any business workflow that can be orchestrated with command line tools.
Key Workflow Concepts
Workflow is a series of orchestrated activities
Workflow activities are isolated
All data and objects are serialized
Objects are strongly typed
Workflows use static scoping
Requirements
Built on .NET Framework 4.0 and
Windows Workflow Foundation
Requires PowerShell 3.0
Requires PowerShell 3.0 remoting
Leverages PowerShell's job
infrastructure
Requirements: Remoting
Workflows connect to machines using WSMan protocol
Connects to the default Workflow session configuration
PS C:> get-pssessionconfiguration
microsoft.powerShell.workflow
Important defaults:
◦ Max persistence storage 10GB
◦ Max memory per shell 1GB
◦ Admin permissions required
Be very careful of changing this configuration
High Level
Workflow Configure-Server
{
#magic happens
}
PS C:> configure-server –pscomputername SRV01
Script
converted to
Workflow
XAML
Workflow
endpoint
Workflow
engine
Limitations and Gotchas
All objects
and data
must be
"serializable"
Must use full
cmdlet and
parameter
names –
these are
activities
No
positional
parameters
No Begin/
Process/End
scriptblocks
No
"eventing"
Limitations and Gotchas
No Traps -
Use
Try/Catch
Not intended
to be
interactive –
don’t use
Write-Host.
No comment
based help -
must use
MAML
formatted
files
Pay close
attention to
scope!
Workflow Architecture
Workflow Engine
PowerShell Client
Session
PowerShell
Workflow
“Service”
WinRM Client
Client
PSRP/PowerShell
Managed Node
Remoting
Commands/API
Operation Host Process
Operations
Host
WSMan/CIM
Managed Node
Building Workflows
Don't
simply
replace
"Function"
with
"Workflow"
Start new
and plan
out your
activities
Minimize
sharing of
data or
variables
across
activities
PowerShell
turns your
workflow
into XAML
Workflow is
a new
command
type in
PowerShell
3.0
PS C:> get-command -commandtype Workflow
Syntax: Sequence
Execute a collection of activities in order
Can be executed with Parallel
Watch out for scope!
Syntax: Sequence
Sequence {
MyCommand1
}
Sequence {
MyCommand2
MyCommand3
MyCommand4
}
This command runs
Then these commands run in sequence
Syntax: Parallel
Execute a collection of activities independently and in parallel
ForEach -Parallel
• The parameter only works in a workflow
• Run a set of commands in parallel for each object in a collection
Parallel key word
• Run a set of commands simultaneously and in parallel
• Runs in a new scope
• Often used to run a series of Sequences
Parallel
Parallel {
MyCommand1
MyCommand2
MyCommand3
Sequence {
MyCommand4
MyCommand5
} #sequence
} #parallel
These commands run in
sequence
Commands and
sequence run
simultaneously
ForEach -Parallel
ForEach -parallel ($item in $object) {
#do something with each object
MyCommand1 $item
MyCommand2 $item
}
For each item in the
collection…
Run these commands
All object processed
simultaneously
Syntax: InlineScript
Send PowerShell commands to remote machine(s)
Runs out-of-process
Runtime command validation
This is really a series of Invoke-Command activities
Use for all other non-activity commands
InlineScript
Workflow New-Audit {
Inlinescript {
$procs = Get-WmiObject Win32_process
$procs | Select-Object ProcessID,Name,
@{Name="RunTime";Expression={(Get-Date) -
$_.ConvertToDateTime($_.CreationDate)}},
@{Name="Owner";Expression={"$($_.GetOwner().Doma
in)$($_.GetOwner().User)"}}}
}
Syntax: Scope and Variables
Workflows uses static scopes, i.e. PowerShell won't
"search" for a variable
Assume each activity is isolated
Can use $Workflow:MyVar for “global” references
• Read-only
• Available from InlineScript
Access "out of scope" variables with $Using:MyVar
Syntax: Common Parameters
All workflows
have a set of
common
parameters They do not need
to be defined
•PSComputerName
•PSCredential
•PSConnectionRetryCo
unt
•PSActionRetryCount
•PSPersist
Syntax: Persistence
Workflows can be
made persistent to
survive interruptions
Planned reboots
Network interruptions
By default entire
workflow restarts
unless…
Set persistence per
activity
•Checkpoint-Workflow
•Persist
•Suspend-Workflow
Set persistence for
the entire workflow
-PSPersist common
parameter
Set to $True:
-pspersist $true
Running Workflows
Load
workflow
Specify
remote
computers
Specify
credentials
Run as a
job
Use a
Workflow
session
Invoke-AsWorkflow
Run any command or expression as a workflow
Run as an InlineScript
Executed from the console
Great for ad-hoc remote management without writing a workflow
Invoke-AsWorkflow -CommandName get-eventlog -
Parameter @{Logname="System";Newest=10;
Entrytype="Error"} -pscomputername $computers -asjob
Workflow Sessions
Run Workflows from within a special PSSession
Workflows can be monitored and managed from within the session
Great for long running workflows or those that might be suspended and
resumed
Session can be disconnected and reconnected
Best Practices
Try to test locally and interactively
Use Write-Verbose for tracing and troubleshooting
Use a workflow-aware editor like the PowerShell ISE
Take advantage of parallelism
Plan your activities…this is not just another way to script
Resources
The Lonely Administrator (http://jdhitsolutions.com/blog)
PowerShell in Depth
http://PowerShell.org
http://blogs.technet.com/b/heyscriptingguy
Thank You
http://jdhitsolutions.com/blog
jhicks@jdhitsolutions.com
@JeffHicks
http://plus.google.com/+JefferyHicks

More Related Content

What's hot (20)

Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
Bruce Coddington
 
Angular Testing
Angular TestingAngular Testing
Angular Testing
Priscila Negreiros
 
What's New in Django 1.6
What's New in Django 1.6What's New in Django 1.6
What's New in Django 1.6
Siva Arunachalam
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
Aircon Chen
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012
slandelle
 
Three Lessons about Gatling and Microservices
Three Lessons about Gatling and MicroservicesThree Lessons about Gatling and Microservices
Three Lessons about Gatling and Microservices
Dragos Manolescu
 
Backbone js
Backbone jsBackbone js
Backbone js
Knoldus Inc.
 
동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍
명신 김
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scala
Sandeep Purohit
 
Why reactive:reactive programming spring 5
Why reactive:reactive programming spring 5Why reactive:reactive programming spring 5
Why reactive:reactive programming spring 5
dnnddane
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
Yakov Fain
 
JavaScript Coding Guidelines
JavaScript Coding GuidelinesJavaScript Coding Guidelines
JavaScript Coding Guidelines
Oleksii Prohonnyi
 
CQRS and Event Sourcing with Axon Framework
CQRS and Event Sourcing with Axon FrameworkCQRS and Event Sourcing with Axon Framework
CQRS and Event Sourcing with Axon Framework
João Rafael Campos da Silva
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
ASIT
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
The CQRS diet
The CQRS dietThe CQRS diet
The CQRS diet
Luismi Cavallé
 
Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7
andrewmriley
 
Marrying angular rails
Marrying angular railsMarrying angular rails
Marrying angular rails
Volker Tietz
 
PostgREST Design Philosophy
PostgREST Design PhilosophyPostgREST Design Philosophy
PostgREST Design Philosophy
begriffs
 
Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
Bruce Coddington
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012
slandelle
 
Three Lessons about Gatling and Microservices
Three Lessons about Gatling and MicroservicesThree Lessons about Gatling and Microservices
Three Lessons about Gatling and Microservices
Dragos Manolescu
 
동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍
명신 김
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scala
Sandeep Purohit
 
Why reactive:reactive programming spring 5
Why reactive:reactive programming spring 5Why reactive:reactive programming spring 5
Why reactive:reactive programming spring 5
dnnddane
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
Yakov Fain
 
JavaScript Coding Guidelines
JavaScript Coding GuidelinesJavaScript Coding Guidelines
JavaScript Coding Guidelines
Oleksii Prohonnyi
 
Learn AJAX at ASIT
Learn AJAX at ASITLearn AJAX at ASIT
Learn AJAX at ASIT
ASIT
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7
andrewmriley
 
Marrying angular rails
Marrying angular railsMarrying angular rails
Marrying angular rails
Volker Tietz
 
PostgREST Design Philosophy
PostgREST Design PhilosophyPostgREST Design Philosophy
PostgREST Design Philosophy
begriffs
 

Viewers also liked (20)

PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
mikepfeiffer
 
No-script PowerShell v2
No-script PowerShell v2No-script PowerShell v2
No-script PowerShell v2
Concentrated Technology
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows Automation
Concentrated Technology
 
Ha & drs gotcha's
Ha & drs gotcha'sHa & drs gotcha's
Ha & drs gotcha's
Concentrated Technology
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Meet Windows PowerShell
Meet Windows PowerShellMeet Windows PowerShell
Meet Windows PowerShell
Concentrated Technology
 
PowerShell and WMI
PowerShell and WMIPowerShell and WMI
PowerShell and WMI
Concentrated Technology
 
Combining output from multiple sources
Combining output from multiple sourcesCombining output from multiple sources
Combining output from multiple sources
Concentrated Technology
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
Chris Conte
 
PS error handling and debugging
PS error handling and debuggingPS error handling and debugging
PS error handling and debugging
Concentrated Technology
 
Implementing dr w. hyper v clustering
Implementing dr w. hyper v clusteringImplementing dr w. hyper v clustering
Implementing dr w. hyper v clustering
Concentrated Technology
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
PowerShell 8tips
PowerShell 8tipsPowerShell 8tips
PowerShell 8tips
Concentrated Technology
 
Best free tools for win database admin
Best free tools for win database adminBest free tools for win database admin
Best free tools for win database admin
Concentrated Technology
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
Salaudeen Rajack
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
Jason Stangroome
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
Concentrated Technology
 
PowerShell crash course
PowerShell crash coursePowerShell crash course
PowerShell crash course
Concentrated Technology
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
mikepfeiffer
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows Automation
Concentrated Technology
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
Chris Conte
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
Concentrated Technology
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
Concentrated Technology
 
Basic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 sessionBasic PowerShell Toolmaking - Spiceworld 2016 session
Basic PowerShell Toolmaking - Spiceworld 2016 session
Rob Dunn
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
Salaudeen Rajack
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
Jason Stangroome
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
Concentrated Technology
 
Ad

Similar to Intro to PowerShell Workflow (20)

PowerShell 3.0 workflows
PowerShell 3.0 workflowsPowerShell 3.0 workflows
PowerShell 3.0 workflows
Ravikanth Chaganti
 
Windows PowerShell Remoting Presentation.pdf
Windows PowerShell Remoting Presentation.pdfWindows PowerShell Remoting Presentation.pdf
Windows PowerShell Remoting Presentation.pdf
Syahri Ramadhan
 
Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0
jsnover1
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
rsnarayanan
 
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
 
Windows PowerShell
Windows PowerShellWindows PowerShell
Windows PowerShell
Orbit One - We create coherence
 
Sunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil phani's take on windows powershell
Sunil phani's take on windows powershell
Sunil Phani
 
PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011
Ravikanth Chaganti
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
Concentrated Technology
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
Introducing PowerShell 3.0
Introducing PowerShell 3.0Introducing PowerShell 3.0
Introducing PowerShell 3.0
Jan Egil Ring
 
PowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdfPowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdf
DataSpace Academy
 
Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power Shell
Microsoft TechNet
 
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Michael Blumenthal (Microsoft MVP)
 
Informatica Power Center - Workflow Manager
Informatica Power Center - Workflow ManagerInformatica Power Center - Workflow Manager
Informatica Power Center - Workflow Manager
ZaranTech LLC
 
A Lap Around PowerShell 3.0
A Lap Around PowerShell 3.0A Lap Around PowerShell 3.0
A Lap Around PowerShell 3.0
Sarah Dutkiewicz
 
PowerShell Remoting
PowerShell RemotingPowerShell Remoting
PowerShell Remoting
Concentrated Technology
 
PowerShell Technical Overview
PowerShell Technical OverviewPowerShell Technical Overview
PowerShell Technical Overview
allandcp
 
Windows Powershell in Action 1st Edition Bruce G. Payette
Windows Powershell in Action 1st Edition Bruce G. PayetteWindows Powershell in Action 1st Edition Bruce G. Payette
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
Introduction to Powershell Version 5
Introduction to Powershell Version 5Introduction to Powershell Version 5
Introduction to Powershell Version 5
Nishtha Kesarwani
 
Windows PowerShell Remoting Presentation.pdf
Windows PowerShell Remoting Presentation.pdfWindows PowerShell Remoting Presentation.pdf
Windows PowerShell Remoting Presentation.pdf
Syahri Ramadhan
 
Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0
jsnover1
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
rsnarayanan
 
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
 
Sunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil phani's take on windows powershell
Sunil phani's take on windows powershell
Sunil Phani
 
PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011PowerShell in the enterprise - TechED India 2011
PowerShell in the enterprise - TechED India 2011
Ravikanth Chaganti
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
Concentrated Technology
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
Introducing PowerShell 3.0
Introducing PowerShell 3.0Introducing PowerShell 3.0
Introducing PowerShell 3.0
Jan Egil Ring
 
PowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdfPowerShell In 2024 And Beyond The Future Of Automation.pdf
PowerShell In 2024 And Beyond The Future Of Automation.pdf
DataSpace Academy
 
Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power Shell
Microsoft TechNet
 
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Michael Blumenthal (Microsoft MVP)
 
Informatica Power Center - Workflow Manager
Informatica Power Center - Workflow ManagerInformatica Power Center - Workflow Manager
Informatica Power Center - Workflow Manager
ZaranTech LLC
 
A Lap Around PowerShell 3.0
A Lap Around PowerShell 3.0A Lap Around PowerShell 3.0
A Lap Around PowerShell 3.0
Sarah Dutkiewicz
 
PowerShell Technical Overview
PowerShell Technical OverviewPowerShell Technical Overview
PowerShell Technical Overview
allandcp
 
Windows Powershell in Action 1st Edition Bruce G. Payette
Windows Powershell in Action 1st Edition Bruce G. PayetteWindows Powershell in Action 1st Edition Bruce G. Payette
Windows Powershell in Action 1st Edition Bruce G. Payette
takabedembe
 
Introduction to Powershell Version 5
Introduction to Powershell Version 5Introduction to Powershell Version 5
Introduction to Powershell Version 5
Nishtha Kesarwani
 
Ad

Recently uploaded (20)

Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 

Intro to PowerShell Workflow

  • 2. Agenda What is Workflow? Workflow Syntax Running Workflows Practical Workflows Best Practices
  • 3. Think! Just because you can use a PowerShell workflow doesn’t mean you should.
  • 4. Definitions – What is a Workflow A robust multi-machine orchestration engine Designed for long running unattended tasks across potentially thousands of machines Persistent states can survive reboots and network interruptions Previously built in Visual Studio
  • 5. Definitions - What is PowerShell Workflow? • Persistence via check points • Suspend and Resume capabilitiesRobust • Parallel tasks • Connection pooling • Connection throttling Performance and Scalability • Use existing cmdlets* • No need to master XAML or use Visual Studio • Built in parameters for multi-machine management PowerShell Based
  • 6. Workflow Scenarios Server deployment Server configuration/remediation User provisioning Private cloud deployments Sharepoint configuration Any business workflow that can be orchestrated with command line tools.
  • 7. Key Workflow Concepts Workflow is a series of orchestrated activities Workflow activities are isolated All data and objects are serialized Objects are strongly typed Workflows use static scoping
  • 8. Requirements Built on .NET Framework 4.0 and Windows Workflow Foundation Requires PowerShell 3.0 Requires PowerShell 3.0 remoting Leverages PowerShell's job infrastructure
  • 9. Requirements: Remoting Workflows connect to machines using WSMan protocol Connects to the default Workflow session configuration PS C:> get-pssessionconfiguration microsoft.powerShell.workflow Important defaults: ◦ Max persistence storage 10GB ◦ Max memory per shell 1GB ◦ Admin permissions required Be very careful of changing this configuration
  • 10. High Level Workflow Configure-Server { #magic happens } PS C:> configure-server –pscomputername SRV01 Script converted to Workflow XAML Workflow endpoint Workflow engine
  • 11. Limitations and Gotchas All objects and data must be "serializable" Must use full cmdlet and parameter names – these are activities No positional parameters No Begin/ Process/End scriptblocks No "eventing"
  • 12. Limitations and Gotchas No Traps - Use Try/Catch Not intended to be interactive – don’t use Write-Host. No comment based help - must use MAML formatted files Pay close attention to scope!
  • 13. Workflow Architecture Workflow Engine PowerShell Client Session PowerShell Workflow “Service” WinRM Client Client PSRP/PowerShell Managed Node Remoting Commands/API Operation Host Process Operations Host WSMan/CIM Managed Node
  • 14. Building Workflows Don't simply replace "Function" with "Workflow" Start new and plan out your activities Minimize sharing of data or variables across activities PowerShell turns your workflow into XAML Workflow is a new command type in PowerShell 3.0 PS C:> get-command -commandtype Workflow
  • 15. Syntax: Sequence Execute a collection of activities in order Can be executed with Parallel Watch out for scope!
  • 16. Syntax: Sequence Sequence { MyCommand1 } Sequence { MyCommand2 MyCommand3 MyCommand4 } This command runs Then these commands run in sequence
  • 17. Syntax: Parallel Execute a collection of activities independently and in parallel ForEach -Parallel • The parameter only works in a workflow • Run a set of commands in parallel for each object in a collection Parallel key word • Run a set of commands simultaneously and in parallel • Runs in a new scope • Often used to run a series of Sequences
  • 18. Parallel Parallel { MyCommand1 MyCommand2 MyCommand3 Sequence { MyCommand4 MyCommand5 } #sequence } #parallel These commands run in sequence Commands and sequence run simultaneously
  • 19. ForEach -Parallel ForEach -parallel ($item in $object) { #do something with each object MyCommand1 $item MyCommand2 $item } For each item in the collection… Run these commands All object processed simultaneously
  • 20. Syntax: InlineScript Send PowerShell commands to remote machine(s) Runs out-of-process Runtime command validation This is really a series of Invoke-Command activities Use for all other non-activity commands
  • 21. InlineScript Workflow New-Audit { Inlinescript { $procs = Get-WmiObject Win32_process $procs | Select-Object ProcessID,Name, @{Name="RunTime";Expression={(Get-Date) - $_.ConvertToDateTime($_.CreationDate)}}, @{Name="Owner";Expression={"$($_.GetOwner().Doma in)$($_.GetOwner().User)"}}} }
  • 22. Syntax: Scope and Variables Workflows uses static scopes, i.e. PowerShell won't "search" for a variable Assume each activity is isolated Can use $Workflow:MyVar for “global” references • Read-only • Available from InlineScript Access "out of scope" variables with $Using:MyVar
  • 23. Syntax: Common Parameters All workflows have a set of common parameters They do not need to be defined •PSComputerName •PSCredential •PSConnectionRetryCo unt •PSActionRetryCount •PSPersist
  • 24. Syntax: Persistence Workflows can be made persistent to survive interruptions Planned reboots Network interruptions By default entire workflow restarts unless… Set persistence per activity •Checkpoint-Workflow •Persist •Suspend-Workflow Set persistence for the entire workflow -PSPersist common parameter Set to $True: -pspersist $true
  • 26. Invoke-AsWorkflow Run any command or expression as a workflow Run as an InlineScript Executed from the console Great for ad-hoc remote management without writing a workflow Invoke-AsWorkflow -CommandName get-eventlog - Parameter @{Logname="System";Newest=10; Entrytype="Error"} -pscomputername $computers -asjob
  • 27. Workflow Sessions Run Workflows from within a special PSSession Workflows can be monitored and managed from within the session Great for long running workflows or those that might be suspended and resumed Session can be disconnected and reconnected
  • 28. Best Practices Try to test locally and interactively Use Write-Verbose for tracing and troubleshooting Use a workflow-aware editor like the PowerShell ISE Take advantage of parallelism Plan your activities…this is not just another way to script
  • 29. Resources The Lonely Administrator (http://jdhitsolutions.com/blog) PowerShell in Depth http://PowerShell.org http://blogs.technet.com/b/heyscriptingguy