SlideShare a Scribd company logo
1 of 53
Download to read offline
1
One man loves PowerShell
once he failed
@gab_km
12th July, 2014
Japan PowerShell meetup #3
2
Who am I?
● an engineer works in an IT services company
● use .NET mainly, love F# in private.
● be interested in Python, D language, ...
● and PowerShell!
3
The topics I will tell you about
● I was bad at PowerShell, but now feel to fit it
● I found the way how to overcome to struggle
4
Once upon a time...
5
Once upon a time...
In this tweet, I have started PowerShell 2
years ago from this time(24/Mar/2011).
6
What made me hard for PowerShell
There were 2 cases I had trouble using
PowerShell:
● I seemed there are a lot of differences in
command system between PowerShell and bat.
● I could not some operations shortly in
PowerShell while I could them in good old bat.
7
In these days...
8
In these days...
I tweeted this in the spring of 2013.
It makes me improve doing in PowerShell that I
tried to write some PS1 things for a year.
9
Case 1
First I wrote bat files which were executed in
booting my PC to run some useful tools like a
mailer, connect file servers or do something
convenient.
10
Case 1
First I wrote bat files which were executed in
booting my PC to run some useful tools like a
mailer, connect file servers or do something
convenient.
              ↓
When I was learning Python, I rewrote these
booting scripts in Python, which helped me to
learn it.
11
Case 1
First I wrote bat files which were executed in
booting my PC to run some useful tools like a
mailer, connect file servers or do something
convenient.
              ↓
When I was learning Python, I rewrote these
booting scripts in Python, which helped me to
learn it.
              ↓
I tried rewriting them in PowerShell again for
my learning PowerShell.
12
Case 2
13
Case 2
Chocolatey is one of the best package managers
for Windows and I like it. As I should connect
using a proxy server in my workplace, this
package manager fails installing. :-(
So I sent a pull request to achieve 'chocolatey
install' with a proxy server.
14
Case 2
Chocolatey is one of the best package managers
for Windows and I like it. As I should connect
using a proxy server in my workplace, this
package manager fails installing. :-(
So I sent a pull request to achieve 'chocolatey
install' with a proxy server.
* As of 12th July, 2014, this pull request is not merged.
15
Case 3
16
Case 3
# Rename all mp4 files with “Last Write Time”
Get-ChildItem |
Where { $_.Name.StartsWith("MAKERNAME") } |
ForEach { Rename-Item $_ -newname ($(Get-ItemProperty
$_).LastWriteTime.ToString("yyyyMMdd_hhmm") + ".MP4") }
17
What gave me the power to the shell
I overcame the troubles in using PowerShell
with seeing the way to do things above.
● File specification and execution
● File operation
● Pipeline
18
What gave me the power to the shell
I overcame the troubles in using PowerShell
with seeing the way to do things above.
● File specification and execution
● File operation
● Pipeline
Even if you are a person who are not good at
PowerShell, the abilities to do the 3 things
above make you break down the obstacle.
19
● File specification and execution
● File operation
● Pipeline
20
File specification and execution
PS> notitle.ps1
This is a script file named 'notitle.ps1' and
created in your current directory.
You input like above to execute it.
If it does well, your terminal shows you
“Hello, there!” as output message.
21
PS> notitle.ps1
notitle.ps1 : 用語 'notitle.ps1' は、コマンドレット、関数、スクリ
プト ファイル、または操作可能なプ
ログラムの名前として認識されません。名前が正しく記述されていることを確認
し、パスが含まれている場合
はそのパスが正しいことを確認してから、再試行してください。
発生場所 行 :1 文字 :1
+ notitle.ps1
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound:
(notitle.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS>
File specification and execution
22
PS> notitle.ps1
notitle.ps1 : 用語 'notitle.ps1' は、コマンドレット、関数、スクリ
プト ファイル、または操作可能なプ
ログラムの名前として認識されません。名前が正しく記述されていることを確認
し、パスが含まれている場合
はそのパスが正しいことを確認してから、再試行してください。
発生場所 行 :1 文字 :1
+ notitle.ps1
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound:
(notitle.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS>
You will see this error message when you simply
replace from .bat commands to .ps1 commands.
File specification and execution
23
To specify files(1)- Absolute path
PS> C:myposhnotitle.ps1
24
To specify files(1)- Absolute path
PS> C:myposhnotitle.ps1
Hello, there!
PS>
This is a foolproof and verbose method.
25
To specify files(2)- Use '.'
PS> .notitle.ps1
26
To specify files(2)- Use '.'
PS> .notitle.ps1
Hello, there!
PS>
When you want to specify a file or a folder in
your current directory, give '.' to the head
of a relative path.
27
Case - You cannot execute a file
PS> $myScript = “C:myposhnotitle.ps1”
PS> $myScript
There are some cases where you cannot execute a
file with the way we have seen.
28
PS> $myScript = “C:myposhnotitle.ps1”
PS> $myScript
C:myposhnotitle.ps1
PS>
Case - You cannot execute a file
29
PS> $myScript = “C:myposhnotitle.ps1”
PS> $myScript
C:myposhnotitle.ps1
PS>
Though we want to execute a file, this way
shows us only the path we set.
Case - You cannot execute a file
30
To execute files(1)- Use '&'
PS> & $myScript
Hello, there!
PS>
In this case, you can pass a path to execute to
an ampersand symbol('&') and you will execute
it.
The ampersand symbol works whether there are
spaces between the symbol and the path or not.
31
To execute files(2)- Use '.'
PS> . $myScript
Hello, there!
PS>
In the same case, when you use a dot symbol(.)
with a path, you will execute it.
This method is called 'Dot-Sourcing'.
32
To execute files(2)- Use '.'
PS> . $myScript
Hello, there!
PS>
In the same case, when you use a dot symbol(.)
with a path, you will execute it.
This method is called 'Dot-Sourcing'.
For more details, you will find when you search
the words “dot sourcing” or ask PowerShell
wizards.( ◜◡◝ )
33
● File specification and execution
● File operation
● Pipeline
34
File operation
● Copy
● Rename
● Delete
There were demands for files to:
35
File operation
● Copy
● Rename
● Delete
There were demands for files to:
Though we can use 'good old' commands from cmd,
we are born to be PowerShell geeks and we are
wannabes to use Cmdlet.
36
Copy files(1)
PS> Copy-Item -Path .notitle.ps1 -Destination C:myetc
PS> ls C:myetc | where Name -eq notitle.ps1
ディレクトリ : C:myetc
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2014/07/11 23:42 31 notitle.ps1
PS>
When we want to copy files, we use Copy-Item.
37
Copy files(2)
PS> Get-ChildItem C:myetc | % { $_.Name }
PS> Copy-Item -Path C:myposhn* -Destination C:myetc
PS> Get-ChildItem C:myetc | % { $_.Name }
As -Path parameter of Copy-Item understands
wildcard notations, we can use this cmdlet as
following:
38
PS> Get-ChildItem C:myetc | % { $_.Name }
PS> Copy-Item -Path C:myposhn* -Destination C:myetc
PS> Get-ChildItem C:myetc | % { $_.Name }
notitle.ps1
nanimoyarukishinai.txt
PS>
Copy files(2)
As -Path parameter of Copy-Item understands
wildcard notations, we can use this cmdlet as
following:
39
Rename files
PS> ls | % { $_.Name }
notitle.ps1
PS> Rename-Item -Path .notitle.ps1 -NewName foobar.ps1
PS> ls | % { $_.Name }
foobar.ps1
PS>
Use Rename-Item to rename files.
40
Delete files
PS> ls | % { $_.Name }
notitle.ps1
PS> Remove-Item .notitle.ps1
PS> ls | % { $_.Name }
PS>
Use Remove-Item to delete files.
41
Delete files
PS> ls | % { $_.Name }
notitle.ps1
PS> Remove-Item .notitle.ps1
PS> ls | % { $_.Name }
PS>
Use Remove-Item to delete files.
In PowerShell, cmdlets are defined by setting
their names on “Verb-Objective” rules, so we
can find them intuitively.
42
● File specification and execution
● File operation
● Pipeline
43
Pipeline
There is a strong relationship like this:
“Associate PowerShell with pipeline,
44
Pipeline
There is a strong relationship like this:
“Associate PowerShell with pipeline,
associate pipeline with F# PowerShell”
45
Pipeline
in my humble opinion.
● filtering
● serial processing
There is a strong relationship like this:
“Associate PowerShell with pipeline,
associate pipeline with F# PowerShell”
When we want to use pipeline, the reason is
classified into 2 broad categories:
46
Pipeline - filtering
@("hoge", "fuga", "bar") | where { $_.Length -eq 4 }
# "hoge"
# "fuga"
Filtering is one of the basis operations for
pipeline.
Returns only the elements of the collection for
which the given condition block returns $True.
47
Pipeline - filtering
@("hoge", "fuga", "bar") | where { $_.Length -eq 4 }
# "hoge"
# "fuga"
Filtering is one of the basis operations for
pipeline.
Returns only the elements of the collection for
which the given condition block returns $True.
$_ is the variable for the current value in the
pipeline.
When I was one of the PowerShell newbies, I had
trouble remembering the variable and searched
again and again...
48
Pipeline - serial processing(1)
@("hoge", "fuga", "bar") | foreach { $_.ToUpper() }
# "HOGE"
# "FUGA"
# “BAR”
Applies the given block for ForEach-Object to
each element of the collection.
49
Pipeline - serial processing(1)
@("hoge", "fuga", "bar") | foreach { $_.ToUpper() }
# "HOGE"
# "FUGA"
# “BAR”
Applies the given block for ForEach-Object to
each element of the collection.
It is similar to the functions map, iter or
something like these in your natural functional
programming languages.
50
Pipeline - serial processing(2)
@(1 .. 3) | % { $_ + 2 }
# 3
# 4
# 5
There is an useful alias for Foreach-Object:
'%' symbol.
51
The topics I told you about
● I was bad at PowerShell, but now feel to fit it
● I found the way how to overcome to struggle
52
The topics I told you about
● I was bad at PowerShell, but now feel to fit it
● I found the way how to overcome to struggle
● File specification and execution
● File operation
● Pipeline
53
The topics I told you about
● I was bad at PowerShell, but now feel to fit it
● I found the way how to overcome to struggle
● File specification and execution
● File operation
● Pipeline
Learn You Your PowerShell
for Great Good!

More Related Content

What's hot

7 Common mistakes in Go and when to avoid them
7 Common mistakes in Go and when to avoid them7 Common mistakes in Go and when to avoid them
7 Common mistakes in Go and when to avoid themSteven Francia
 
Mission ImpAnsible - NSM at (RobotFrame)work
Mission ImpAnsible - NSM at (RobotFrame)work Mission ImpAnsible - NSM at (RobotFrame)work
Mission ImpAnsible - NSM at (RobotFrame)work Adam Przybyła
 
Unix Basics
Unix BasicsUnix Basics
Unix BasicsDr.Ravi
 
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Steven Francia
 
Unit 8
Unit 8Unit 8
Unit 8siddr
 
Infrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleInfrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleice799
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with GoSteven Francia
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
Wait what? Postgresql can do that?
Wait what? Postgresql can do that?Wait what? Postgresql can do that?
Wait what? Postgresql can do that?All Things Open
 
3.3. Database honeypot
3.3. Database honeypot3.3. Database honeypot
3.3. Database honeypotdefconmoscow
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 

What's hot (20)

Linux final exam
Linux final examLinux final exam
Linux final exam
 
7 Common mistakes in Go and when to avoid them
7 Common mistakes in Go and when to avoid them7 Common mistakes in Go and when to avoid them
7 Common mistakes in Go and when to avoid them
 
Unix 2 en
Unix 2 enUnix 2 en
Unix 2 en
 
Mission ImpAnsible - NSM at (RobotFrame)work
Mission ImpAnsible - NSM at (RobotFrame)work Mission ImpAnsible - NSM at (RobotFrame)work
Mission ImpAnsible - NSM at (RobotFrame)work
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...Go for Object Oriented Programmers or Object Oriented Programming without Obj...
Go for Object Oriented Programmers or Object Oriented Programming without Obj...
 
Unit 8
Unit 8Unit 8
Unit 8
 
Batch conv3.2 1
Batch conv3.2 1Batch conv3.2 1
Batch conv3.2 1
 
Infrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleInfrastructure as code might be literally impossible
Infrastructure as code might be literally impossible
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Getting Started with Go
Getting Started with GoGetting Started with Go
Getting Started with Go
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Wait what? Postgresql can do that?
Wait what? Postgresql can do that?Wait what? Postgresql can do that?
Wait what? Postgresql can do that?
 
Lpt lopsa
Lpt lopsaLpt lopsa
Lpt lopsa
 
Shell script-sec
Shell script-secShell script-sec
Shell script-sec
 
3.3. Database honeypot
3.3. Database honeypot3.3. Database honeypot
3.3. Database honeypot
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 

Similar to One man loves powershell once he failed

cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Ilya Haykinson
 
Document Library Folder Operations User Guide
Document Library Folder Operations User GuideDocument Library Folder Operations User Guide
Document Library Folder Operations User GuideIT Industry
 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow softwareAnubhav Jain
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Eviljaredhaight
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)Concentrated Technology
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfClapperboardCinemaPV
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in pythonKarin Lagesen
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts Pavan Babu .G
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 

Similar to One man loves powershell once he failed (20)

cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Puppi. Puppet strings to the shell
Puppi. Puppet strings to the shellPuppi. Puppet strings to the shell
Puppi. Puppet strings to the shell
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
 
Document Library Folder Operations User Guide
Document Library Folder Operations User GuideDocument Library Folder Operations User Guide
Document Library Folder Operations User Guide
 
Puppet quick start guide
Puppet quick start guidePuppet quick start guide
Puppet quick start guide
 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow software
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
 
Python1
Python1Python1
Python1
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in python
 
Perl_Part3
Perl_Part3Perl_Part3
Perl_Part3
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

One man loves powershell once he failed

  • 1. 1 One man loves PowerShell once he failed @gab_km 12th July, 2014 Japan PowerShell meetup #3
  • 2. 2 Who am I? ● an engineer works in an IT services company ● use .NET mainly, love F# in private. ● be interested in Python, D language, ... ● and PowerShell!
  • 3. 3 The topics I will tell you about ● I was bad at PowerShell, but now feel to fit it ● I found the way how to overcome to struggle
  • 4. 4 Once upon a time...
  • 5. 5 Once upon a time... In this tweet, I have started PowerShell 2 years ago from this time(24/Mar/2011).
  • 6. 6 What made me hard for PowerShell There were 2 cases I had trouble using PowerShell: ● I seemed there are a lot of differences in command system between PowerShell and bat. ● I could not some operations shortly in PowerShell while I could them in good old bat.
  • 8. 8 In these days... I tweeted this in the spring of 2013. It makes me improve doing in PowerShell that I tried to write some PS1 things for a year.
  • 9. 9 Case 1 First I wrote bat files which were executed in booting my PC to run some useful tools like a mailer, connect file servers or do something convenient.
  • 10. 10 Case 1 First I wrote bat files which were executed in booting my PC to run some useful tools like a mailer, connect file servers or do something convenient.               ↓ When I was learning Python, I rewrote these booting scripts in Python, which helped me to learn it.
  • 11. 11 Case 1 First I wrote bat files which were executed in booting my PC to run some useful tools like a mailer, connect file servers or do something convenient.               ↓ When I was learning Python, I rewrote these booting scripts in Python, which helped me to learn it.               ↓ I tried rewriting them in PowerShell again for my learning PowerShell.
  • 13. 13 Case 2 Chocolatey is one of the best package managers for Windows and I like it. As I should connect using a proxy server in my workplace, this package manager fails installing. :-( So I sent a pull request to achieve 'chocolatey install' with a proxy server.
  • 14. 14 Case 2 Chocolatey is one of the best package managers for Windows and I like it. As I should connect using a proxy server in my workplace, this package manager fails installing. :-( So I sent a pull request to achieve 'chocolatey install' with a proxy server. * As of 12th July, 2014, this pull request is not merged.
  • 16. 16 Case 3 # Rename all mp4 files with “Last Write Time” Get-ChildItem | Where { $_.Name.StartsWith("MAKERNAME") } | ForEach { Rename-Item $_ -newname ($(Get-ItemProperty $_).LastWriteTime.ToString("yyyyMMdd_hhmm") + ".MP4") }
  • 17. 17 What gave me the power to the shell I overcame the troubles in using PowerShell with seeing the way to do things above. ● File specification and execution ● File operation ● Pipeline
  • 18. 18 What gave me the power to the shell I overcame the troubles in using PowerShell with seeing the way to do things above. ● File specification and execution ● File operation ● Pipeline Even if you are a person who are not good at PowerShell, the abilities to do the 3 things above make you break down the obstacle.
  • 19. 19 ● File specification and execution ● File operation ● Pipeline
  • 20. 20 File specification and execution PS> notitle.ps1 This is a script file named 'notitle.ps1' and created in your current directory. You input like above to execute it. If it does well, your terminal shows you “Hello, there!” as output message.
  • 21. 21 PS> notitle.ps1 notitle.ps1 : 用語 'notitle.ps1' は、コマンドレット、関数、スクリ プト ファイル、または操作可能なプ ログラムの名前として認識されません。名前が正しく記述されていることを確認 し、パスが含まれている場合 はそのパスが正しいことを確認してから、再試行してください。 発生場所 行 :1 文字 :1 + notitle.ps1 + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (notitle.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS> File specification and execution
  • 22. 22 PS> notitle.ps1 notitle.ps1 : 用語 'notitle.ps1' は、コマンドレット、関数、スクリ プト ファイル、または操作可能なプ ログラムの名前として認識されません。名前が正しく記述されていることを確認 し、パスが含まれている場合 はそのパスが正しいことを確認してから、再試行してください。 発生場所 行 :1 文字 :1 + notitle.ps1 + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (notitle.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS> You will see this error message when you simply replace from .bat commands to .ps1 commands. File specification and execution
  • 23. 23 To specify files(1)- Absolute path PS> C:myposhnotitle.ps1
  • 24. 24 To specify files(1)- Absolute path PS> C:myposhnotitle.ps1 Hello, there! PS> This is a foolproof and verbose method.
  • 25. 25 To specify files(2)- Use '.' PS> .notitle.ps1
  • 26. 26 To specify files(2)- Use '.' PS> .notitle.ps1 Hello, there! PS> When you want to specify a file or a folder in your current directory, give '.' to the head of a relative path.
  • 27. 27 Case - You cannot execute a file PS> $myScript = “C:myposhnotitle.ps1” PS> $myScript There are some cases where you cannot execute a file with the way we have seen.
  • 28. 28 PS> $myScript = “C:myposhnotitle.ps1” PS> $myScript C:myposhnotitle.ps1 PS> Case - You cannot execute a file
  • 29. 29 PS> $myScript = “C:myposhnotitle.ps1” PS> $myScript C:myposhnotitle.ps1 PS> Though we want to execute a file, this way shows us only the path we set. Case - You cannot execute a file
  • 30. 30 To execute files(1)- Use '&' PS> & $myScript Hello, there! PS> In this case, you can pass a path to execute to an ampersand symbol('&') and you will execute it. The ampersand symbol works whether there are spaces between the symbol and the path or not.
  • 31. 31 To execute files(2)- Use '.' PS> . $myScript Hello, there! PS> In the same case, when you use a dot symbol(.) with a path, you will execute it. This method is called 'Dot-Sourcing'.
  • 32. 32 To execute files(2)- Use '.' PS> . $myScript Hello, there! PS> In the same case, when you use a dot symbol(.) with a path, you will execute it. This method is called 'Dot-Sourcing'. For more details, you will find when you search the words “dot sourcing” or ask PowerShell wizards.( ◜◡◝ )
  • 33. 33 ● File specification and execution ● File operation ● Pipeline
  • 34. 34 File operation ● Copy ● Rename ● Delete There were demands for files to:
  • 35. 35 File operation ● Copy ● Rename ● Delete There were demands for files to: Though we can use 'good old' commands from cmd, we are born to be PowerShell geeks and we are wannabes to use Cmdlet.
  • 36. 36 Copy files(1) PS> Copy-Item -Path .notitle.ps1 -Destination C:myetc PS> ls C:myetc | where Name -eq notitle.ps1 ディレクトリ : C:myetc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 2014/07/11 23:42 31 notitle.ps1 PS> When we want to copy files, we use Copy-Item.
  • 37. 37 Copy files(2) PS> Get-ChildItem C:myetc | % { $_.Name } PS> Copy-Item -Path C:myposhn* -Destination C:myetc PS> Get-ChildItem C:myetc | % { $_.Name } As -Path parameter of Copy-Item understands wildcard notations, we can use this cmdlet as following:
  • 38. 38 PS> Get-ChildItem C:myetc | % { $_.Name } PS> Copy-Item -Path C:myposhn* -Destination C:myetc PS> Get-ChildItem C:myetc | % { $_.Name } notitle.ps1 nanimoyarukishinai.txt PS> Copy files(2) As -Path parameter of Copy-Item understands wildcard notations, we can use this cmdlet as following:
  • 39. 39 Rename files PS> ls | % { $_.Name } notitle.ps1 PS> Rename-Item -Path .notitle.ps1 -NewName foobar.ps1 PS> ls | % { $_.Name } foobar.ps1 PS> Use Rename-Item to rename files.
  • 40. 40 Delete files PS> ls | % { $_.Name } notitle.ps1 PS> Remove-Item .notitle.ps1 PS> ls | % { $_.Name } PS> Use Remove-Item to delete files.
  • 41. 41 Delete files PS> ls | % { $_.Name } notitle.ps1 PS> Remove-Item .notitle.ps1 PS> ls | % { $_.Name } PS> Use Remove-Item to delete files. In PowerShell, cmdlets are defined by setting their names on “Verb-Objective” rules, so we can find them intuitively.
  • 42. 42 ● File specification and execution ● File operation ● Pipeline
  • 43. 43 Pipeline There is a strong relationship like this: “Associate PowerShell with pipeline,
  • 44. 44 Pipeline There is a strong relationship like this: “Associate PowerShell with pipeline, associate pipeline with F# PowerShell”
  • 45. 45 Pipeline in my humble opinion. ● filtering ● serial processing There is a strong relationship like this: “Associate PowerShell with pipeline, associate pipeline with F# PowerShell” When we want to use pipeline, the reason is classified into 2 broad categories:
  • 46. 46 Pipeline - filtering @("hoge", "fuga", "bar") | where { $_.Length -eq 4 } # "hoge" # "fuga" Filtering is one of the basis operations for pipeline. Returns only the elements of the collection for which the given condition block returns $True.
  • 47. 47 Pipeline - filtering @("hoge", "fuga", "bar") | where { $_.Length -eq 4 } # "hoge" # "fuga" Filtering is one of the basis operations for pipeline. Returns only the elements of the collection for which the given condition block returns $True. $_ is the variable for the current value in the pipeline. When I was one of the PowerShell newbies, I had trouble remembering the variable and searched again and again...
  • 48. 48 Pipeline - serial processing(1) @("hoge", "fuga", "bar") | foreach { $_.ToUpper() } # "HOGE" # "FUGA" # “BAR” Applies the given block for ForEach-Object to each element of the collection.
  • 49. 49 Pipeline - serial processing(1) @("hoge", "fuga", "bar") | foreach { $_.ToUpper() } # "HOGE" # "FUGA" # “BAR” Applies the given block for ForEach-Object to each element of the collection. It is similar to the functions map, iter or something like these in your natural functional programming languages.
  • 50. 50 Pipeline - serial processing(2) @(1 .. 3) | % { $_ + 2 } # 3 # 4 # 5 There is an useful alias for Foreach-Object: '%' symbol.
  • 51. 51 The topics I told you about ● I was bad at PowerShell, but now feel to fit it ● I found the way how to overcome to struggle
  • 52. 52 The topics I told you about ● I was bad at PowerShell, but now feel to fit it ● I found the way how to overcome to struggle ● File specification and execution ● File operation ● Pipeline
  • 53. 53 The topics I told you about ● I was bad at PowerShell, but now feel to fit it ● I found the way how to overcome to struggle ● File specification and execution ● File operation ● Pipeline Learn You Your PowerShell for Great Good!