SlideShare una empresa de Scribd logo
1 de 21
Automating boring
tasks with Powershell
Works on Windows only
Alban Gérôme
@albangerome
MeasureCamp Amsterdam
13 April 2019
Life is too short to
spend on boring tasks
…but someone
has got to do it
@albangerome
…let’s automate it!
@albangerome
MS-DOS
dir c:myfolder*.js /b > list.txt
This returns a list of all Javascript file
names in a specific folder in a text file
@albangerome
MS-DOS
If you liked it, wait until
you see Powershell
@albangerome
Manipulate IE with Powershell
$a = new-object –com "Internet Explorer"
$a.visible = $true
# $a.silent = $true
$a.navigate http://www.somewebsite.com
function wait{
start-sleep –milliseconds 100
}
$b = $false
do{
while($a.busy –or $a.readyState –lt 4){wait}
$c = "myElementID"
$d = $a.document
$e = $d.IHTMLDocument3_getElementById($c)
if($e –ne $null){
$f = "(function(a, b){"
$f += "var c = document.createEvent('CustomEvent');"
$f += "c.initCustomEvent('change', !0, !1, undefined);"
$f += "$(a).val(b)[0].dispatchEvent(c);"
$f += "})('#$c', 'password')"
$d.parentWindow.execScript($f, "javascript")
}
if($e.value.length –gt 0){$b = $true}
}until($b –eq $true)
Opens Internet Explorer and goes to
http://www.somewebsite.com
The code keeps checking 10 times per second
whether the page has fully loaded or fully
rendered
When the page has finished rendering it
searches for a text field with id =
“myElementID”
Then it sets “password” as the value of that
text field and fires the change DOM event
@albangerome
Manipulate IE with Powershell
$a = new-object –com "Internet Explorer"
$a.visible = $true
# $a.silent = $true
$a.navigate http://www.somewebsite.com
function wait{
start-sleep –milliseconds 100
}
$b = $false
do{
while($a.busy –or $a.readyState –lt 4){wait}
$c = "myElementID"
$d = $a.document
$e = $d.IHTMLDocument3_getElementById($c)
if($e –ne $null){
$f = "(function(a, b){"
$f += "var c = document.createEvent('CustomEvent');"
$f += "c.initCustomEvent('change', !0, !1, undefined);"
$f += "$(a).val(b)[0].dispatchEvent(c);"
$f += "})('#$c', 'password')"
$d.parentWindow.execScript($f, "javascript")
}
if($e.value.length –gt 0){$b = $true}
}until($b –eq $true)
Every variable must start with $. That’s how
Powershell distinguishes between functions, also
called cmdlet, and variables.
You assign a value to a variable using the equal
sign. You cannot use the equal sign to test when
two variables are equal
You can concatenate strings with the plus sign
and build a string over several lines using the
plus-equal combo (+=)
You can include a variable inside a string without
needing extra string concatenating code
@albangerome
Manipulate IE with Powershell
$a = new-object –com "Internet Explorer"
$a.visible = $true
# $a.silent = $true
$a.navigate http://www.somewebsite.com
function wait{
start-sleep –milliseconds 100
}
$b = $false
do{
while($a.busy –or $a.readyState –lt 4){wait}
$c = "myElementID"
$d = $a.document
$e = $d.IHTMLDocument3_getElementById($c)
if($e –ne $null){
$f = "(function(a, b){"
$f += "var c = document.createEvent('CustomEvent');"
$f += "c.initCustomEvent('change', !0, !1, undefined);"
$f += "$(a).val(b)[0].dispatchEvent(c);"
$f += "})('#$c', 'password')"
$d.parentWindow.execScript($f, "javascript")
}
if($e.value.length –gt 0){$b = $true}
}until($b –eq $true)
Booleans: $true, $false, $null
Operators:
• -or: or
• -ne: is not equal to
• -eq: is equal to
• -lt: is less than
• -gt: is greater than
• -match: does a regular expression match
• and many more
@albangerome
Manipulate IE with Powershell
$a = new-object –com "Internet Explorer"
$a.visible = $true
# $a.silent = $true
$a.navigate http://www.somewebsite.com
function wait{
start-sleep –milliseconds 100
}
$b = $false
do{
while($a.busy –or $a.readyState –lt 4){wait}
$c = "myElementID"
$d = $a.document
$e = $d.IHTMLDocument3_getElementById($c)
if($e –ne $null){
$f = "(function(a, b){"
$f += "var c = document.createEvent('CustomEvent');"
$f += "c.initCustomEvent('change', !0, !1, undefined);"
$f += "$(a).val(b)[0].dispatchEvent(c);"
$f += "})('#$c', 'password')"
$d.parentWindow.execScript($f, "javascript")
}
if($e.value.length –gt 0){$b = $true}
}until($b –eq $true)
Controlled loops:
• while – keeps looping until the expected
condition is no longer true
• do-until – keeps looping until the expected
condition is true
• for – loops for a predefined number of times.
The loop can break on demand if a specific
condition is met
• foreach – loops through each item of a list
Powershell can execute Javascript, jQuery code
(if the page has loaded jQuery) or a blend of both
vanilla Javascript and jQuery. That code can
simulate browser actions such as clicks on
specific buttons for example
@albangerome
Manipulate IE with Powershell
$a = new-object –com "Internet Explorer"
$a.visible = $true
# $a.silent = $true
$a.navigate http://www.somewebsite.com
function wait{
start-sleep –milliseconds 100
}
$b = $false
do{
#step 1
}until($b –eq $true)
do{
#step 2
}until($b –eq $true)
do{
#step 3
}until($b –eq $true)
…
You can create complex scenarios where each
do-until block targets manipulates a page
element such as:
• a link
• a text field
• a drop-down
… and assign an action to this element such as:
• a click
• passing a value
• selecting a pre-existing value
@albangerome
What I use Powershell for
• Takes screen shots
• Create, read, update, delete, rename, move, zip, unzip files
• Make IE go through minute scenarios and interact with the pages
• And so much more I have not tried yet
• Send emails
• Start Excel, Word, Powerpoint and start VBA macros in them
• Interface with a database and run SQL on it
@albangerome
The good and the bad
I don’t like so much:
• The syntax can be complex but I am on the
start of my learning curve still
• Somewhat cryptic error messages
• Some commands require adding extra
brackets to clarify the scope of what the
function executes to
• Powershell books are often humongous
• Some Powershell scripts require running
them in admin mode which may be disabled
• Admins often disable features so your
mileage may vary
I like:
• Short command names (often <5 letters)
• Command-chaining aka piping
• Flexible, case-insensitive syntax
• You can call functions with or without
brackets around the parameters
• You can create your own functions
• It comes preinstalled on Windows machines
• It can save you a ton of time and reduce
human error drastically
@albangerome
Starting Powershell
@albangerome
• Type powershell in the search bar near the start menu
• Start MS-DOS by typing cmd and then powershell
• Searching for powershell.exe – there are several versions
Dankuwel!
http://www.albangerome.com
@albangerome

Más contenido relacionado

La actualidad más candente

Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricksambiescent
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017Ryan Weaver
 
Auto tools
Auto toolsAuto tools
Auto tools祺 周
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIDirk Ginader
 
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIsNicolas Blanco
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the webRemy Sharp
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Vagmi Mudumbai
 
Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)Chris Charlton
 
(ARC307) Infrastructure as Code | AWS re:Invent 2014
(ARC307) Infrastructure as Code | AWS re:Invent 2014(ARC307) Infrastructure as Code | AWS re:Invent 2014
(ARC307) Infrastructure as Code | AWS re:Invent 2014Amazon Web Services
 
Useful things to do with jQuery
Useful things to do with jQueryUseful things to do with jQuery
Useful things to do with jQueryJames Bubb
 
A piece of sugar in your client-side development
A piece of sugar in your client-side developmentA piece of sugar in your client-side development
A piece of sugar in your client-side developmentNicolas Blanco
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYusuke Wada
 
So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!Matt Turnure
 

La actualidad más candente (20)

Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
Auto tools
Auto toolsAuto tools
Auto tools
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
 
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
 
Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)Sassy CSS (part 2) (Drupal Camp LA 2013)
Sassy CSS (part 2) (Drupal Camp LA 2013)
 
(ARC307) Infrastructure as Code | AWS re:Invent 2014
(ARC307) Infrastructure as Code | AWS re:Invent 2014(ARC307) Infrastructure as Code | AWS re:Invent 2014
(ARC307) Infrastructure as Code | AWS re:Invent 2014
 
Useful things to do with jQuery
Useful things to do with jQueryUseful things to do with jQuery
Useful things to do with jQuery
 
A piece of sugar in your client-side development
A piece of sugar in your client-side developmentA piece of sugar in your client-side development
A piece of sugar in your client-side development
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
 
So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!So long, jQuery, and thanks for all the fish!
So long, jQuery, and thanks for all the fish!
 

Similar a Automating boring tasks with Powershell

Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksNate Abele
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tipsanubavam-techkt
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practicesbrinsknaps
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in RailsBenjamin Vandgrift
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design PatternsTrevorBurnham
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Rails, Postgres, Angular, and Bootstrap: The Power Stack
Rails, Postgres, Angular, and Bootstrap: The Power StackRails, Postgres, Angular, and Bootstrap: The Power Stack
Rails, Postgres, Angular, and Bootstrap: The Power StackDavid Copeland
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHPwebhostingguy
 

Similar a Automating boring tasks with Powershell (20)

Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in Rails
 
Ruby gems
Ruby gemsRuby gems
Ruby gems
 
DrupalCon jQuery
DrupalCon jQueryDrupalCon jQuery
DrupalCon jQuery
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
 
Rails, Postgres, Angular, and Bootstrap: The Power Stack
Rails, Postgres, Angular, and Bootstrap: The Power StackRails, Postgres, Angular, and Bootstrap: The Power Stack
Rails, Postgres, Angular, and Bootstrap: The Power Stack
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
 
Stored Procedure
Stored ProcedureStored Procedure
Stored Procedure
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 

Más de Alban Gérôme

Avoir de l’impact, autrement
Avoir de l’impact, autrementAvoir de l’impact, autrement
Avoir de l’impact, autrementAlban Gérôme
 
Earning more as a Digital or Web Analyst
Earning more as a Digital or Web AnalystEarning more as a Digital or Web Analyst
Earning more as a Digital or Web AnalystAlban Gérôme
 
Is it just me, or the C-suite doesn't care about data?
Is it just me, or the C-suite doesn't care about data?Is it just me, or the C-suite doesn't care about data?
Is it just me, or the C-suite doesn't care about data?Alban Gérôme
 
Cracking trading cards packs and web analytics
Cracking trading cards packs and web analyticsCracking trading cards packs and web analytics
Cracking trading cards packs and web analyticsAlban Gérôme
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QAAlban Gérôme
 
The us vs the uk web analytics job slideshare
The us vs the uk web analytics job slideshareThe us vs the uk web analytics job slideshare
The us vs the uk web analytics job slideshareAlban Gérôme
 
Implementing Web Analytics on Single Page Applications
Implementing Web Analytics on Single Page ApplicationsImplementing Web Analytics on Single Page Applications
Implementing Web Analytics on Single Page ApplicationsAlban Gérôme
 
Influence and Persuasion
Influence and PersuasionInfluence and Persuasion
Influence and PersuasionAlban Gérôme
 
Reshaping the Hype Cycle
Reshaping the Hype CycleReshaping the Hype Cycle
Reshaping the Hype CycleAlban Gérôme
 
Claiming credit for being data-driven
Claiming credit for being data-drivenClaiming credit for being data-driven
Claiming credit for being data-drivenAlban Gérôme
 
Acceptance, Accessible, Applicable et Auditable
Acceptance, Accessible, Applicable et AuditableAcceptance, Accessible, Applicable et Auditable
Acceptance, Accessible, Applicable et AuditableAlban Gérôme
 
Acceptance, Accessible, Actionable and Auditable
Acceptance, Accessible, Actionable and AuditableAcceptance, Accessible, Actionable and Auditable
Acceptance, Accessible, Actionable and AuditableAlban Gérôme
 
Are you still working for a data justified company?
Are you still working for a data justified company?Are you still working for a data justified company?
Are you still working for a data justified company?Alban Gérôme
 
Build your own analytics power tools
Build your own analytics power toolsBuild your own analytics power tools
Build your own analytics power toolsAlban Gérôme
 
Is data visualisation bullshit?
Is data visualisation bullshit?Is data visualisation bullshit?
Is data visualisation bullshit?Alban Gérôme
 
Acceptance, accessible, actionable and auditable
Acceptance, accessible, actionable and auditableAcceptance, accessible, actionable and auditable
Acceptance, accessible, actionable and auditableAlban Gérôme
 

Más de Alban Gérôme (20)

Avoir de l’impact, autrement
Avoir de l’impact, autrementAvoir de l’impact, autrement
Avoir de l’impact, autrement
 
Earning more as a Digital or Web Analyst
Earning more as a Digital or Web AnalystEarning more as a Digital or Web Analyst
Earning more as a Digital or Web Analyst
 
Is it just me, or the C-suite doesn't care about data?
Is it just me, or the C-suite doesn't care about data?Is it just me, or the C-suite doesn't care about data?
Is it just me, or the C-suite doesn't care about data?
 
Cracking trading cards packs and web analytics
Cracking trading cards packs and web analyticsCracking trading cards packs and web analytics
Cracking trading cards packs and web analytics
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QA
 
The us vs the uk web analytics job slideshare
The us vs the uk web analytics job slideshareThe us vs the uk web analytics job slideshare
The us vs the uk web analytics job slideshare
 
Implementing Web Analytics on Single Page Applications
Implementing Web Analytics on Single Page ApplicationsImplementing Web Analytics on Single Page Applications
Implementing Web Analytics on Single Page Applications
 
Tagging differently
Tagging differentlyTagging differently
Tagging differently
 
Influence and Persuasion
Influence and PersuasionInfluence and Persuasion
Influence and Persuasion
 
Reshaping the Hype Cycle
Reshaping the Hype CycleReshaping the Hype Cycle
Reshaping the Hype Cycle
 
Claiming credit for being data-driven
Claiming credit for being data-drivenClaiming credit for being data-driven
Claiming credit for being data-driven
 
Acceptance, Accessible, Applicable et Auditable
Acceptance, Accessible, Applicable et AuditableAcceptance, Accessible, Applicable et Auditable
Acceptance, Accessible, Applicable et Auditable
 
Acceptance, Accessible, Actionable and Auditable
Acceptance, Accessible, Actionable and AuditableAcceptance, Accessible, Actionable and Auditable
Acceptance, Accessible, Actionable and Auditable
 
Logic or emotions
Logic or emotionsLogic or emotions
Logic or emotions
 
Hub and spoke model
Hub and spoke modelHub and spoke model
Hub and spoke model
 
Are you still working for a data justified company?
Are you still working for a data justified company?Are you still working for a data justified company?
Are you still working for a data justified company?
 
Persuasion
PersuasionPersuasion
Persuasion
 
Build your own analytics power tools
Build your own analytics power toolsBuild your own analytics power tools
Build your own analytics power tools
 
Is data visualisation bullshit?
Is data visualisation bullshit?Is data visualisation bullshit?
Is data visualisation bullshit?
 
Acceptance, accessible, actionable and auditable
Acceptance, accessible, actionable and auditableAcceptance, accessible, actionable and auditable
Acceptance, accessible, actionable and auditable
 

Último

Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...HyderabadDolls
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1ranjankumarbehera14
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...kumargunjan9515
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...HyderabadDolls
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.pptibrahimabdi22
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样wsppdmt
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...nirzagarg
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...HyderabadDolls
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...kumargunjan9515
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...SOFTTECHHUB
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...Health
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowgargpaaro
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfSayantanBiswas37
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...gajnagarg
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...nirzagarg
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numberssuginr1
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 

Último (20)

Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
 
Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1Lecture_2_Deep_Learning_Overview-newone1
Lecture_2_Deep_Learning_Overview-newone1
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
如何办理英国诺森比亚大学毕业证(NU毕业证书)成绩单原件一模一样
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Computer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdfComputer science Sql cheat sheet.pdf.pdf
Computer science Sql cheat sheet.pdf.pdf
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 

Automating boring tasks with Powershell

  • 1. Automating boring tasks with Powershell Works on Windows only Alban Gérôme @albangerome MeasureCamp Amsterdam 13 April 2019
  • 2.
  • 3. Life is too short to spend on boring tasks …but someone has got to do it @albangerome
  • 5.
  • 6. MS-DOS dir c:myfolder*.js /b > list.txt This returns a list of all Javascript file names in a specific folder in a text file @albangerome
  • 7. MS-DOS If you liked it, wait until you see Powershell @albangerome
  • 8.
  • 9. Manipulate IE with Powershell $a = new-object –com "Internet Explorer" $a.visible = $true # $a.silent = $true $a.navigate http://www.somewebsite.com function wait{ start-sleep –milliseconds 100 } $b = $false do{ while($a.busy –or $a.readyState –lt 4){wait} $c = "myElementID" $d = $a.document $e = $d.IHTMLDocument3_getElementById($c) if($e –ne $null){ $f = "(function(a, b){" $f += "var c = document.createEvent('CustomEvent');" $f += "c.initCustomEvent('change', !0, !1, undefined);" $f += "$(a).val(b)[0].dispatchEvent(c);" $f += "})('#$c', 'password')" $d.parentWindow.execScript($f, "javascript") } if($e.value.length –gt 0){$b = $true} }until($b –eq $true) Opens Internet Explorer and goes to http://www.somewebsite.com The code keeps checking 10 times per second whether the page has fully loaded or fully rendered When the page has finished rendering it searches for a text field with id = “myElementID” Then it sets “password” as the value of that text field and fires the change DOM event @albangerome
  • 10. Manipulate IE with Powershell $a = new-object –com "Internet Explorer" $a.visible = $true # $a.silent = $true $a.navigate http://www.somewebsite.com function wait{ start-sleep –milliseconds 100 } $b = $false do{ while($a.busy –or $a.readyState –lt 4){wait} $c = "myElementID" $d = $a.document $e = $d.IHTMLDocument3_getElementById($c) if($e –ne $null){ $f = "(function(a, b){" $f += "var c = document.createEvent('CustomEvent');" $f += "c.initCustomEvent('change', !0, !1, undefined);" $f += "$(a).val(b)[0].dispatchEvent(c);" $f += "})('#$c', 'password')" $d.parentWindow.execScript($f, "javascript") } if($e.value.length –gt 0){$b = $true} }until($b –eq $true) Every variable must start with $. That’s how Powershell distinguishes between functions, also called cmdlet, and variables. You assign a value to a variable using the equal sign. You cannot use the equal sign to test when two variables are equal You can concatenate strings with the plus sign and build a string over several lines using the plus-equal combo (+=) You can include a variable inside a string without needing extra string concatenating code @albangerome
  • 11. Manipulate IE with Powershell $a = new-object –com "Internet Explorer" $a.visible = $true # $a.silent = $true $a.navigate http://www.somewebsite.com function wait{ start-sleep –milliseconds 100 } $b = $false do{ while($a.busy –or $a.readyState –lt 4){wait} $c = "myElementID" $d = $a.document $e = $d.IHTMLDocument3_getElementById($c) if($e –ne $null){ $f = "(function(a, b){" $f += "var c = document.createEvent('CustomEvent');" $f += "c.initCustomEvent('change', !0, !1, undefined);" $f += "$(a).val(b)[0].dispatchEvent(c);" $f += "})('#$c', 'password')" $d.parentWindow.execScript($f, "javascript") } if($e.value.length –gt 0){$b = $true} }until($b –eq $true) Booleans: $true, $false, $null Operators: • -or: or • -ne: is not equal to • -eq: is equal to • -lt: is less than • -gt: is greater than • -match: does a regular expression match • and many more @albangerome
  • 12. Manipulate IE with Powershell $a = new-object –com "Internet Explorer" $a.visible = $true # $a.silent = $true $a.navigate http://www.somewebsite.com function wait{ start-sleep –milliseconds 100 } $b = $false do{ while($a.busy –or $a.readyState –lt 4){wait} $c = "myElementID" $d = $a.document $e = $d.IHTMLDocument3_getElementById($c) if($e –ne $null){ $f = "(function(a, b){" $f += "var c = document.createEvent('CustomEvent');" $f += "c.initCustomEvent('change', !0, !1, undefined);" $f += "$(a).val(b)[0].dispatchEvent(c);" $f += "})('#$c', 'password')" $d.parentWindow.execScript($f, "javascript") } if($e.value.length –gt 0){$b = $true} }until($b –eq $true) Controlled loops: • while – keeps looping until the expected condition is no longer true • do-until – keeps looping until the expected condition is true • for – loops for a predefined number of times. The loop can break on demand if a specific condition is met • foreach – loops through each item of a list Powershell can execute Javascript, jQuery code (if the page has loaded jQuery) or a blend of both vanilla Javascript and jQuery. That code can simulate browser actions such as clicks on specific buttons for example @albangerome
  • 13. Manipulate IE with Powershell $a = new-object –com "Internet Explorer" $a.visible = $true # $a.silent = $true $a.navigate http://www.somewebsite.com function wait{ start-sleep –milliseconds 100 } $b = $false do{ #step 1 }until($b –eq $true) do{ #step 2 }until($b –eq $true) do{ #step 3 }until($b –eq $true) … You can create complex scenarios where each do-until block targets manipulates a page element such as: • a link • a text field • a drop-down … and assign an action to this element such as: • a click • passing a value • selecting a pre-existing value @albangerome
  • 14.
  • 15. What I use Powershell for • Takes screen shots • Create, read, update, delete, rename, move, zip, unzip files • Make IE go through minute scenarios and interact with the pages • And so much more I have not tried yet • Send emails • Start Excel, Word, Powerpoint and start VBA macros in them • Interface with a database and run SQL on it @albangerome
  • 16.
  • 17. The good and the bad I don’t like so much: • The syntax can be complex but I am on the start of my learning curve still • Somewhat cryptic error messages • Some commands require adding extra brackets to clarify the scope of what the function executes to • Powershell books are often humongous • Some Powershell scripts require running them in admin mode which may be disabled • Admins often disable features so your mileage may vary I like: • Short command names (often <5 letters) • Command-chaining aka piping • Flexible, case-insensitive syntax • You can call functions with or without brackets around the parameters • You can create your own functions • It comes preinstalled on Windows machines • It can save you a ton of time and reduce human error drastically @albangerome
  • 18.
  • 19. Starting Powershell @albangerome • Type powershell in the search bar near the start menu • Start MS-DOS by typing cmd and then powershell • Searching for powershell.exe – there are several versions
  • 20.