SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Windows Powershell

                                        Kurze Einführung in
                                        Windows Powershell



Software: Planen. Entwickeln. Testen.
Was ist Windows Powershell?

Eine von Microsoft entwickelte Alternative
zum Kommandozeilenprogramm «cmd» und
Windows Host Script

Sehr mächtig (powerful)




Software: Planen. Entwickeln. Testen.
                                        2
Eigenschaften
• Ist Objekt basierend (nicht Text basierend)
• Basiert auf .net
• Hat vollen Zugriff auf .net Framework
• Ab Windows 7 vorinstalliert
• Kommt mit «Entwicklungsumgebung» inkl.
  Debugger.
• Ist «Sicherheitsbewusst» (Skripte lassen sich
  nicht ohne weiteres ausführen, Skripts
  müssen signiert sein, etc.)

Software: Planen. Entwickeln. Testen.
                                                        3
Eigenschaften
• Cmdlets («Command-lets» ) als kleinste
  Funktionseinheit
• Benennungsschema: Verb-Substantiv
         – Get-help
         – Get-process
• Case insensitiv
• Hat viele Alias
         – «dir» für «get-childItem»
         – «cd» für «set-location»
• Alias können selber erzeugt werden
• Variable beginnen mit «$»

Software: Planen. Entwickeln. Testen.
                                                        4
«Piping»

• «Piping» («|») ist wichtig
        Get-process | sort-object –property id | more


• “$_”: Als Platzhalter für das aktuelle Objekt.
  Offizielle Definition für “$_.” das aktuelle
  Piplineobjekt
        Get-Service | where {$_.status -eq "Running" }




Software: Planen. Entwickeln. Testen.
                                                         5
Definierte Variable
     Variable Name         Description
                           The current pipeline object; used in script blocks, filters, the process clause of functions, where-object, foreach-object and
     $_                    switch
     $^                    contains the first token of the last line input into the shell
     $$                    contains the last token of last line input into the shell
     $?                    Contains the success/fail status of the last statement
     $Args                 Used in creating functions that require parameters
     $Env:Path             Environmental Path to files.
     $Error                If an error occurred, the object is saved in the $error PowerShell variable
     $foreach              Refers to the enumerator in a foreach loop.
     $HOME                 The user's home directory; set to %HOMEDRIVE%%HOMEPATH%
     $Input                Input piped to a function or code block
     $Match                A hash table consisting of items found by the -match operator.
     $MyInvocation         Information about the currently script or command-line
     $Host                 Information about the currently executing host
     $LastExitCode         The exit code of the last native application to run
     $true                 Boolean TRUE
     $false                Boolean FALSE
     $null                 A null object
     $OFS                  Output Field Separator, used when converting an array to a string. By default, this is set to the space character
                           The identifier for the shell. This value is used by the shell to determine the ExecutionPolicy and what profiles are run at
     $ShellID              startup.
     $StackTrace           contains detailed stack trace information about the last error


Software: Planen. Entwickeln. Testen.
                                                                                                                            6
Get-Help

•      Get-help
•      Get-help set-location
•      Get-help set-location –full
•      Get-help set-location –example




Software: Planen. Entwickeln. Testen.
                                                   7
Get-Command

• Get-command
• Get-command | more
•      Get-command | where-object {$_.CommandType -eq «Alias»}
       (get-alias macht dasselbe)




Software: Planen. Entwickeln. Testen.
                                                             8
Weitere Befehle

• Variable Zuweisung: $a = get-command
• Get-member (get-command | get-member)
• Get-random




Software: Planen. Entwickeln. Testen.
                                                          9
Aufpassen

• Set-ExecutePolicy remoteSigned
• Programm Start wenn es Leerzeichen im
  Pfad hat: «&» voranstellen
                &«Pfad mit BlankProg.exe»
• Es braucht immer einen Pfadnamen:
                Myprogram inputfile.txt 
                Myprogram .inputfile.txt 
• Vergleiche: eq, ne, gt, etc. (NICHT =!, >=,
  etc)

Software: Planen. Entwickeln. Testen.
                                                    10
Kleine Anwendung

• 100 Zufallszahlen zwischen 0 und 50
  erzeugen:
                         for ($i=0; $i –le 99; $i++){get-random –maximum 50}

• In Variable schreiben
                         $a = for ($i=0; $i –le 99; $i++){get-random –maximum 50}

• Ausgabe auf Datei:
                         $a | Out-file –filepath «c:workrandom.txt»




Software: Planen. Entwickeln. Testen.
                                                                        11
Powershell IDE

•      Script erzeugen
•      Script debuggen (break points etc)
•      Befehle manuell eingeben
•      Powershell Fenster starten




Software: Planen. Entwickeln. Testen.
                                                         12
«dot Source» a Script

Statt Scriptaufruf
        «c:pfadscript.ps1»
Diesen Aufruf:
        «. c:pfadscript.ps1» (Beachte Punkt und Blank)
 Die Variablen, die innerhalb des Scirpts
definiert sind, stehen nach Ablauf des
Scripts zur Verfügung. (sie sind global
geworden)

Software: Planen. Entwickeln. Testen.
                                                      13
Webseiten
•      http://de.wikipedia.org/wiki/Windows_PowerShell
•      http://technet.microsoft.com/en-us/scriptcenter/dd742419
•      http://technet.microsoft.com/en-us/library/ee177003.aspx
•      http://www.computerperformance.co.uk/powershell/index.htm

•      Quick Referenz:
         –     http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7097


•      http://www.powershellpro.com/




Software: Planen. Entwickeln. Testen.
                                                                                   14

Weitere ähnliche Inhalte

Was ist angesagt?

Whitebox testing-phpughh
Whitebox testing-phpughhWhitebox testing-phpughh
Whitebox testing-phpughhWebcsonsultsEU
 
Agiles Testen
Agiles TestenAgiles Testen
Agiles Testenoose
 
Testen mit, durch und in Scrum
Testen mit, durch und in ScrumTesten mit, durch und in Scrum
Testen mit, durch und in ScrumFrank Düsterbeck
 
Continous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickelnContinous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickelnMartin Seibert
 
Hightway to Hell - Responsive Webdesign Testen
Hightway to Hell - Responsive Webdesign TestenHightway to Hell - Responsive Webdesign Testen
Hightway to Hell - Responsive Webdesign TestenPeter Rozek
 
Software-Tests in PHP-Anwendungen
Software-Tests in PHP-AnwendungenSoftware-Tests in PHP-Anwendungen
Software-Tests in PHP-AnwendungenGjero Krsteski
 
Kontinuierliche Integration
Kontinuierliche IntegrationKontinuierliche Integration
Kontinuierliche IntegrationJohannes Weber
 
DevDay 2016 Keynote - Die Evolution agiler Software Entwicklung
DevDay 2016 Keynote - Die Evolution agiler Software EntwicklungDevDay 2016 Keynote - Die Evolution agiler Software Entwicklung
DevDay 2016 Keynote - Die Evolution agiler Software EntwicklungMarc Müller
 
Whitepaper QF-Test: GUI Testautomatisierung macht Spaß
Whitepaper QF-Test: GUI Testautomatisierung macht SpaßWhitepaper QF-Test: GUI Testautomatisierung macht Spaß
Whitepaper QF-Test: GUI Testautomatisierung macht SpaßClaudia Baur
 
Webanwendungen testen
Webanwendungen testenWebanwendungen testen
Webanwendungen testenBoris Köster
 
2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und TestsDaniel Fisher
 

Was ist angesagt? (13)

Whitebox testing-phpughh
Whitebox testing-phpughhWhitebox testing-phpughh
Whitebox testing-phpughh
 
Agiles Testen
Agiles TestenAgiles Testen
Agiles Testen
 
Testen mit, durch und in Scrum
Testen mit, durch und in ScrumTesten mit, durch und in Scrum
Testen mit, durch und in Scrum
 
Agents of D.E.V.O.P.S
Agents of D.E.V.O.P.SAgents of D.E.V.O.P.S
Agents of D.E.V.O.P.S
 
Continous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickelnContinous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickeln
 
Hightway to Hell - Responsive Webdesign Testen
Hightway to Hell - Responsive Webdesign TestenHightway to Hell - Responsive Webdesign Testen
Hightway to Hell - Responsive Webdesign Testen
 
Software-Tests in PHP-Anwendungen
Software-Tests in PHP-AnwendungenSoftware-Tests in PHP-Anwendungen
Software-Tests in PHP-Anwendungen
 
Kontinuierliche Integration
Kontinuierliche IntegrationKontinuierliche Integration
Kontinuierliche Integration
 
DevDay 2016 Keynote - Die Evolution agiler Software Entwicklung
DevDay 2016 Keynote - Die Evolution agiler Software EntwicklungDevDay 2016 Keynote - Die Evolution agiler Software Entwicklung
DevDay 2016 Keynote - Die Evolution agiler Software Entwicklung
 
Whitepaper QF-Test: GUI Testautomatisierung macht Spaß
Whitepaper QF-Test: GUI Testautomatisierung macht SpaßWhitepaper QF-Test: GUI Testautomatisierung macht Spaß
Whitepaper QF-Test: GUI Testautomatisierung macht Spaß
 
objectiF extrem
objectiF extremobjectiF extrem
objectiF extrem
 
Webanwendungen testen
Webanwendungen testenWebanwendungen testen
Webanwendungen testen
 
2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests2005 - NRW Conf: Design, Entwicklung und Tests
2005 - NRW Conf: Design, Entwicklung und Tests
 

Ähnlich wie Creasoft - Windows powershell

OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...NETWAYS
 
Einführung in Puppet und Vagrant
Einführung in Puppet und VagrantEinführung in Puppet und Vagrant
Einführung in Puppet und Vagrants0enke
 
Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Jan Gehring
 
Abläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenAbläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenChristian Münch
 
Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"schellsoft
 
Schweine latein-vortrag
Schweine latein-vortragSchweine latein-vortrag
Schweine latein-vortragRamon Wartala
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit antroskakori
 
DDEV - Eine lokale Entwicklungsumgebung
DDEV - Eine lokale EntwicklungsumgebungDDEV - Eine lokale Entwicklungsumgebung
DDEV - Eine lokale EntwicklungsumgebungFrank Schmittlein
 
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10Ralf Sigmund
 
JsUnconf 2014
JsUnconf 2014JsUnconf 2014
JsUnconf 2014emrox
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit RustJens Siebert
 
An Introduction to Ruby
An Introduction to RubyAn Introduction to Ruby
An Introduction to RubyJonathan Weiss
 
Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)Chris Michael Klinger
 
Backend-Services mit Rust
Backend-Services mit RustBackend-Services mit Rust
Backend-Services mit RustJens Siebert
 

Ähnlich wie Creasoft - Windows powershell (20)

OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
Testing tools
Testing toolsTesting tools
Testing tools
 
Einführung in Docker
Einführung in DockerEinführung in Docker
Einführung in Docker
 
Einführung in Puppet und Vagrant
Einführung in Puppet und VagrantEinführung in Puppet und Vagrant
Einführung in Puppet und Vagrant
 
Node.js
Node.jsNode.js
Node.js
 
Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex
 
Abläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenAbläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisieren
 
Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"
 
Schweine latein-vortrag
Schweine latein-vortragSchweine latein-vortrag
Schweine latein-vortrag
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit ant
 
Windows Powershell
Windows PowershellWindows Powershell
Windows Powershell
 
DDEV - Eine lokale Entwicklungsumgebung
DDEV - Eine lokale EntwicklungsumgebungDDEV - Eine lokale Entwicklungsumgebung
DDEV - Eine lokale Entwicklungsumgebung
 
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10
Wjax integrationsprojekte auf dem weg zur continuous delivery 2011 11-10
 
JsUnconf 2014
JsUnconf 2014JsUnconf 2014
JsUnconf 2014
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit Rust
 
An Introduction to Ruby
An Introduction to RubyAn Introduction to Ruby
An Introduction to Ruby
 
Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1
 
Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)Introduction to Apache Maven 3 (German)
Introduction to Apache Maven 3 (German)
 
Backend-Services mit Rust
Backend-Services mit RustBackend-Services mit Rust
Backend-Services mit Rust
 

Creasoft - Windows powershell

  • 1. Windows Powershell Kurze Einführung in Windows Powershell Software: Planen. Entwickeln. Testen.
  • 2. Was ist Windows Powershell? Eine von Microsoft entwickelte Alternative zum Kommandozeilenprogramm «cmd» und Windows Host Script Sehr mächtig (powerful) Software: Planen. Entwickeln. Testen. 2
  • 3. Eigenschaften • Ist Objekt basierend (nicht Text basierend) • Basiert auf .net • Hat vollen Zugriff auf .net Framework • Ab Windows 7 vorinstalliert • Kommt mit «Entwicklungsumgebung» inkl. Debugger. • Ist «Sicherheitsbewusst» (Skripte lassen sich nicht ohne weiteres ausführen, Skripts müssen signiert sein, etc.) Software: Planen. Entwickeln. Testen. 3
  • 4. Eigenschaften • Cmdlets («Command-lets» ) als kleinste Funktionseinheit • Benennungsschema: Verb-Substantiv – Get-help – Get-process • Case insensitiv • Hat viele Alias – «dir» für «get-childItem» – «cd» für «set-location» • Alias können selber erzeugt werden • Variable beginnen mit «$» Software: Planen. Entwickeln. Testen. 4
  • 5. «Piping» • «Piping» («|») ist wichtig Get-process | sort-object –property id | more • “$_”: Als Platzhalter für das aktuelle Objekt. Offizielle Definition für “$_.” das aktuelle Piplineobjekt Get-Service | where {$_.status -eq "Running" } Software: Planen. Entwickeln. Testen. 5
  • 6. Definierte Variable Variable Name Description The current pipeline object; used in script blocks, filters, the process clause of functions, where-object, foreach-object and $_ switch $^ contains the first token of the last line input into the shell $$ contains the last token of last line input into the shell $? Contains the success/fail status of the last statement $Args Used in creating functions that require parameters $Env:Path Environmental Path to files. $Error If an error occurred, the object is saved in the $error PowerShell variable $foreach Refers to the enumerator in a foreach loop. $HOME The user's home directory; set to %HOMEDRIVE%%HOMEPATH% $Input Input piped to a function or code block $Match A hash table consisting of items found by the -match operator. $MyInvocation Information about the currently script or command-line $Host Information about the currently executing host $LastExitCode The exit code of the last native application to run $true Boolean TRUE $false Boolean FALSE $null A null object $OFS Output Field Separator, used when converting an array to a string. By default, this is set to the space character The identifier for the shell. This value is used by the shell to determine the ExecutionPolicy and what profiles are run at $ShellID startup. $StackTrace contains detailed stack trace information about the last error Software: Planen. Entwickeln. Testen. 6
  • 7. Get-Help • Get-help • Get-help set-location • Get-help set-location –full • Get-help set-location –example Software: Planen. Entwickeln. Testen. 7
  • 8. Get-Command • Get-command • Get-command | more • Get-command | where-object {$_.CommandType -eq «Alias»} (get-alias macht dasselbe) Software: Planen. Entwickeln. Testen. 8
  • 9. Weitere Befehle • Variable Zuweisung: $a = get-command • Get-member (get-command | get-member) • Get-random Software: Planen. Entwickeln. Testen. 9
  • 10. Aufpassen • Set-ExecutePolicy remoteSigned • Programm Start wenn es Leerzeichen im Pfad hat: «&» voranstellen &«Pfad mit BlankProg.exe» • Es braucht immer einen Pfadnamen: Myprogram inputfile.txt  Myprogram .inputfile.txt  • Vergleiche: eq, ne, gt, etc. (NICHT =!, >=, etc) Software: Planen. Entwickeln. Testen. 10
  • 11. Kleine Anwendung • 100 Zufallszahlen zwischen 0 und 50 erzeugen: for ($i=0; $i –le 99; $i++){get-random –maximum 50} • In Variable schreiben $a = for ($i=0; $i –le 99; $i++){get-random –maximum 50} • Ausgabe auf Datei: $a | Out-file –filepath «c:workrandom.txt» Software: Planen. Entwickeln. Testen. 11
  • 12. Powershell IDE • Script erzeugen • Script debuggen (break points etc) • Befehle manuell eingeben • Powershell Fenster starten Software: Planen. Entwickeln. Testen. 12
  • 13. «dot Source» a Script Statt Scriptaufruf «c:pfadscript.ps1» Diesen Aufruf: «. c:pfadscript.ps1» (Beachte Punkt und Blank)  Die Variablen, die innerhalb des Scirpts definiert sind, stehen nach Ablauf des Scripts zur Verfügung. (sie sind global geworden) Software: Planen. Entwickeln. Testen. 13
  • 14. Webseiten • http://de.wikipedia.org/wiki/Windows_PowerShell • http://technet.microsoft.com/en-us/scriptcenter/dd742419 • http://technet.microsoft.com/en-us/library/ee177003.aspx • http://www.computerperformance.co.uk/powershell/index.htm • Quick Referenz: – http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7097 • http://www.powershellpro.com/ Software: Planen. Entwickeln. Testen. 14