SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
The Power Of PowerShell: Advanced
   Kurt Roggen, Technical Consultant,
   Devoteam



kurt.roggen@devoteam.be
Agenda

 • PowerShell Basics
  •   PS Syntax
  •   Pipeline
  •   3 cmdlets to know/remember
 • PowerShell Advanced
  •   Functions
  •   Modules
  •   Comment Based Help
  •   Accepting PS Objects from the pipeline
  •   Creating PS Objects
PS Cmdlet Syntax




  verb-<ID>SingularNoun
   Get-Service, New-Mailbox, Get-ADUser, Get-Disk, Get-VM,
   Start-Process, Stop-Process, New-NALun, Get-AzureVM, ...
3 cmdlets to know/remember!!

PowerShell is self-discoverable using
1. Get-Command
2. Get-Help
3. Get-Member
1. Get-Help

 Displays help information
 Get-Help
 Get-Help get-service
 Get-Help get-service -examples
 Get-Help get-service -detailed
 Get-Help get-service -full
 Get-Help get-service -online
 Get-Help get-service -parameter ComputerName
 Get-Help * -parameter ComputerName
 Get-Help about_wildcards
 Alias: help
2. Get-Command

Displays all commands (cmdlet, function, alias)
Get-Command
Get-Command -verb get
Get-Command -noun service
Get-Command -module ActiveDirectory
Get-Command -CmdType cmdlet
Alias: gcm
3. Get-Member

Displays all MemberTypes (Property,Methods,...)
Get-Service | Get-Member
Get-Member –InputType (Get-Service)
Get-Member –MemberType Method
Get-Member –MemberType Property
Alias: gm
Modules
Modules

Collections of cmdlets
Portable
Stored in file system
  %windir%System32WindowsPoweshell1.0Modules

Module Cmdlets:
 New-Module, Get-Module, Import-Module, Remove-Module

Module Manifest Cmdlets:
  New-ModuleManifest , Test-ModuleManifest
Functions
Creating Functions

 function Get-OS
{
    param(
     [string[]]$ComputerName = $env:COMPUTERNAME
    )

      gwmi Win32_OperatingSystem -ComputerName $ComputerName
}




    PS C:> Get-OS -ComputerName “MyClient1”, ”MyClient2”
Creating Modules

Modules Location:
%windir%System32WindowsPoweshell1.0Modules

Create a PS module folder (eg: MyModule)

Save PS module with extension .PSM1 instead of .PS1 (MyModule.psm1)
  •   PS module folder name must have same name as PS module file basename
Comment Based Help
Comment Based Help
 Function Get-OS
 {
  <#
 .SYNOPSIS
           <toktok>
 .DESCRIPTION
       <toktok>
 .PARAMETER ComputerName
       <toktok>
 .EXAMPLE
       Get-OS
 .LINK
       http://mysite.com/get-os/
 #>
     Param (
            [string]$ComputerName,
            [switch]$Details
     )
 }
Accepting Pipeline Input
Accepting Pipeline Input

 function Get-OS
 {
     param(
       [Parameter(ValueFromPipeLine=$true)]
       [string[]]$ComputerName = $env:COMPUTERNAME
     )
   PROCESS
   {
       <blabla>
   }
 }
Creating PS Objects
Create PS Object
$Obj = New-Object –Type PSObject
$Obj   |   Add-Member   –Name   ComputerName   –Value   $ComputerName   –Type   NoteProperty
$Obj   |   Add-Member   –Name   OS             –Value   $OS             –Type   NoteProperty
$Obj   |   Add-Member   –Name   ServicePack    –Value   $ServicePack    –Type   NoteProperty
$Obj   |   Add-Member   –Name   Version        –Value   $ComputerName   –Type   NoteProperty



Return PS Object (to pipeline)
$Obj
Conclusion

PowerShell is the future present
PowerShell is Self-discoverable
 Remember 3 basic commands
Reuse code using functions in modules


It’s easy - Try it, you’ll see!
The Power of PowerShell: Advanced

Contenu connexe

Tendances

Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbSmartTools
 
Enable https (1) Tibco document
Enable https (1) Tibco document Enable https (1) Tibco document
Enable https (1) Tibco document Eodishaorg Paribaar
 
PowerShell 2 remoting
PowerShell 2 remotingPowerShell 2 remoting
PowerShell 2 remotingjonathanmedd
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for BeginnersArie Bregman
 
(Practical) linux 101
(Practical) linux 101(Practical) linux 101
(Practical) linux 101Arie Bregman
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104Arie Bregman
 
How to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceHow to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceTaehee Jang
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationTasawr Interactive
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017Shuji Watanabe
 
Linux commd
Linux commdLinux commd
Linux commdragav03
 
Linux commd
Linux commdLinux commd
Linux commdragav03
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)MongoDB
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Inputprimeteacher32
 

Tendances (20)

Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
Enable https (1) Tibco document
Enable https (1) Tibco document Enable https (1) Tibco document
Enable https (1) Tibco document
 
PowerShell 2 remoting
PowerShell 2 remotingPowerShell 2 remoting
PowerShell 2 remoting
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for Beginners
 
Linux class 9 15 oct 2021-5
Linux class 9   15 oct 2021-5Linux class 9   15 oct 2021-5
Linux class 9 15 oct 2021-5
 
Linux class 10 15 oct 2021-6
Linux class 10   15 oct 2021-6Linux class 10   15 oct 2021-6
Linux class 10 15 oct 2021-6
 
(Practical) linux 101
(Practical) linux 101(Practical) linux 101
(Practical) linux 101
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104
 
Comets notes
Comets notesComets notes
Comets notes
 
ASM
ASMASM
ASM
 
How to manage Microsoft Azure with open source
How to manage Microsoft Azure with open sourceHow to manage Microsoft Azure with open source
How to manage Microsoft Azure with open source
 
Powershell enum
Powershell enumPowershell enum
Powershell enum
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql Replication
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Sahu
SahuSahu
Sahu
 
Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017
 
Linux commd
Linux commdLinux commd
Linux commd
 
Linux commd
Linux commdLinux commd
Linux commd
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 

En vedette

Process of science
Process of scienceProcess of science
Process of scienceQuanina Quan
 
Seminar meningitis
Seminar meningitisSeminar meningitis
Seminar meningitisbowosaja
 
Monopsony market structure
Monopsony market structureMonopsony market structure
Monopsony market structureTravis Klein
 
Virtualization Myths Infographic
Virtualization Myths Infographic Virtualization Myths Infographic
Virtualization Myths Infographic EMC
 
Mit2 092 f09_lec10
Mit2 092 f09_lec10Mit2 092 f09_lec10
Mit2 092 f09_lec10Rahman Hakim
 
Thurs god wills it crusdades
Thurs god wills it crusdadesThurs god wills it crusdades
Thurs god wills it crusdadesTravis Klein
 
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIES
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIESBIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIES
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIESSrichattra Chaivongvilan
 
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...EMC
 
Linux kursu-erzurum
Linux kursu-erzurumLinux kursu-erzurum
Linux kursu-erzurumsersld67
 
4 things you_cannot_recover
4 things you_cannot_recover4 things you_cannot_recover
4 things you_cannot_recoverChandan Dubey
 
อังกฤษ
อังกฤษอังกฤษ
อังกฤษjojowhisky
 
บทที่ 4
บทที่ 4บทที่ 4
บทที่ 4einscream
 
Dia de la_democracia
Dia de la_democraciaDia de la_democracia
Dia de la_democraciaLauma1416
 
Stomp presentation v1.5.1
Stomp presentation v1.5.1Stomp presentation v1.5.1
Stomp presentation v1.5.1Patrick Cannon
 
White Paper: Advanced Cyber Analytics with Greenplum Database
White Paper: Advanced Cyber Analytics with Greenplum DatabaseWhite Paper: Advanced Cyber Analytics with Greenplum Database
White Paper: Advanced Cyber Analytics with Greenplum DatabaseEMC
 
Chapter 5 presentation
Chapter 5 presentationChapter 5 presentation
Chapter 5 presentationayurkosky
 

En vedette (20)

Process of science
Process of scienceProcess of science
Process of science
 
Seminar meningitis
Seminar meningitisSeminar meningitis
Seminar meningitis
 
El fax inés
El fax inésEl fax inés
El fax inés
 
Monopsony market structure
Monopsony market structureMonopsony market structure
Monopsony market structure
 
Virtualization Myths Infographic
Virtualization Myths Infographic Virtualization Myths Infographic
Virtualization Myths Infographic
 
Mit2 092 f09_lec10
Mit2 092 f09_lec10Mit2 092 f09_lec10
Mit2 092 f09_lec10
 
Animal power pont
Animal power pontAnimal power pont
Animal power pont
 
Thurs god wills it crusdades
Thurs god wills it crusdadesThurs god wills it crusdades
Thurs god wills it crusdades
 
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIES
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIESBIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIES
BIOENERGY TECHNOLOGY STATUS IN THAILAND: CHALLENGES AND OPPORTUNITIES
 
Jose gafas
Jose gafasJose gafas
Jose gafas
 
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...
Improve Patient Care and Reduce IT Costs with Vendor Neutral Archiving and Cl...
 
Linux kursu-erzurum
Linux kursu-erzurumLinux kursu-erzurum
Linux kursu-erzurum
 
4 things you_cannot_recover
4 things you_cannot_recover4 things you_cannot_recover
4 things you_cannot_recover
 
อังกฤษ
อังกฤษอังกฤษ
อังกฤษ
 
บทที่ 4
บทที่ 4บทที่ 4
บทที่ 4
 
Dia de la_democracia
Dia de la_democraciaDia de la_democracia
Dia de la_democracia
 
Stomp presentation v1.5.1
Stomp presentation v1.5.1Stomp presentation v1.5.1
Stomp presentation v1.5.1
 
Real process
Real processReal process
Real process
 
White Paper: Advanced Cyber Analytics with Greenplum Database
White Paper: Advanced Cyber Analytics with Greenplum DatabaseWhite Paper: Advanced Cyber Analytics with Greenplum Database
White Paper: Advanced Cyber Analytics with Greenplum Database
 
Chapter 5 presentation
Chapter 5 presentationChapter 5 presentation
Chapter 5 presentation
 

Similaire à The Power of PowerShell: Advanced

ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingKurt Roggen [BE]
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubEssam Salah
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersBoulos Dib
 
Power shell training
Power shell trainingPower shell training
Power shell trainingDavid Brabant
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEHitesh Mohapatra
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4JoeDinaso
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!walk2talk srl
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101Thomas Lee
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidMatthew Johnson
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellConcentrated Technology
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2Bryan Cafferky
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009rsnarayanan
 
PowerShell Fundamentals
PowerShell FundamentalsPowerShell Fundamentals
PowerShell Fundamentalsmozdzen
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellPhan Hien
 

Similaire à The Power of PowerShell: Advanced (20)

ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell Toolmaking
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
PowerShell Remoting
PowerShell RemotingPowerShell Remoting
PowerShell Remoting
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Windows PowerShell
Windows PowerShellWindows PowerShell
Windows PowerShell
 
PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
 
Powershell
PowershellPowershell
Powershell
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
 
PowerShell Fundamentals
PowerShell FundamentalsPowerShell Fundamentals
PowerShell Fundamentals
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShell
 

Plus de Microsoft TechNet - Belgium and Luxembourg

Plus de Microsoft TechNet - Belgium and Luxembourg (20)

Windows 10: all you need to know!
Windows 10: all you need to know!Windows 10: all you need to know!
Windows 10: all you need to know!
 
Configuration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
Configuration Manager 2012 – Compliance Settings 101 - Tim de KeukelaereConfiguration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
Configuration Manager 2012 – Compliance Settings 101 - Tim de Keukelaere
 
Windows 8.1 a closer look
Windows 8.1 a closer lookWindows 8.1 a closer look
Windows 8.1 a closer look
 
So you’ve successfully installed SCOM… Now what.
So you’ve successfully installed SCOM… Now what.So you’ve successfully installed SCOM… Now what.
So you’ve successfully installed SCOM… Now what.
 
Data Leakage Prevention
Data Leakage PreventionData Leakage Prevention
Data Leakage Prevention
 
Deploying and managing ConfigMgr Clients
Deploying and managing ConfigMgr ClientsDeploying and managing ConfigMgr Clients
Deploying and managing ConfigMgr Clients
 
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
Self Service BI anno 2013 – Where Do We Come From and Where Are We Going?
 
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware UpdatingHands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
Hands on with Hyper-V Clustering Maintenance Mode & Cluster Aware Updating
 
SCEP 2012 inside SCCM 2012
SCEP 2012 inside SCCM 2012SCEP 2012 inside SCCM 2012
SCEP 2012 inside SCCM 2012
 
Jump start your application monitoring with APM
Jump start your application monitoring with APMJump start your application monitoring with APM
Jump start your application monitoring with APM
 
What’s new in Lync Server 2013: Persistent Chat
What’s new in Lync Server 2013: Persistent ChatWhat’s new in Lync Server 2013: Persistent Chat
What’s new in Lync Server 2013: Persistent Chat
 
What's new for Lync 2013 Clients & Devices
What's new for Lync 2013 Clients & DevicesWhat's new for Lync 2013 Clients & Devices
What's new for Lync 2013 Clients & Devices
 
Office 365 ProPlus: Click-to-run deployment and management
Office 365 ProPlus: Click-to-run deployment and managementOffice 365 ProPlus: Click-to-run deployment and management
Office 365 ProPlus: Click-to-run deployment and management
 
Office 365 Identity Management options
Office 365 Identity Management options Office 365 Identity Management options
Office 365 Identity Management options
 
SharePoint Installation and Upgrade: Untangling Your Options
SharePoint Installation and Upgrade: Untangling Your Options SharePoint Installation and Upgrade: Untangling Your Options
SharePoint Installation and Upgrade: Untangling Your Options
 
The application model in real life
The application model in real lifeThe application model in real life
The application model in real life
 
Microsoft private cloud with Cisco and Netapp - Flexpod solution
Microsoft private cloud with Cisco and Netapp -  Flexpod solutionMicrosoft private cloud with Cisco and Netapp -  Flexpod solution
Microsoft private cloud with Cisco and Netapp - Flexpod solution
 
Managing Windows RT devices in the Enterprise
Managing Windows RT devices in the Enterprise Managing Windows RT devices in the Enterprise
Managing Windows RT devices in the Enterprise
 
Moving from Device Centric to a User Centric Management
Moving from Device Centric to a User Centric Management Moving from Device Centric to a User Centric Management
Moving from Device Centric to a User Centric Management
 
Network Management in System Center 2012 SP1 - VMM
Network Management in System Center 2012  SP1 - VMM Network Management in System Center 2012  SP1 - VMM
Network Management in System Center 2012 SP1 - VMM
 

The Power of PowerShell: Advanced

  • 1. The Power Of PowerShell: Advanced Kurt Roggen, Technical Consultant, Devoteam kurt.roggen@devoteam.be
  • 2. Agenda • PowerShell Basics • PS Syntax • Pipeline • 3 cmdlets to know/remember • PowerShell Advanced • Functions • Modules • Comment Based Help • Accepting PS Objects from the pipeline • Creating PS Objects
  • 3.
  • 4. PS Cmdlet Syntax verb-<ID>SingularNoun Get-Service, New-Mailbox, Get-ADUser, Get-Disk, Get-VM, Start-Process, Stop-Process, New-NALun, Get-AzureVM, ...
  • 5. 3 cmdlets to know/remember!! PowerShell is self-discoverable using 1. Get-Command 2. Get-Help 3. Get-Member
  • 6. 1. Get-Help Displays help information Get-Help Get-Help get-service Get-Help get-service -examples Get-Help get-service -detailed Get-Help get-service -full Get-Help get-service -online Get-Help get-service -parameter ComputerName Get-Help * -parameter ComputerName Get-Help about_wildcards Alias: help
  • 7. 2. Get-Command Displays all commands (cmdlet, function, alias) Get-Command Get-Command -verb get Get-Command -noun service Get-Command -module ActiveDirectory Get-Command -CmdType cmdlet Alias: gcm
  • 8. 3. Get-Member Displays all MemberTypes (Property,Methods,...) Get-Service | Get-Member Get-Member –InputType (Get-Service) Get-Member –MemberType Method Get-Member –MemberType Property Alias: gm
  • 10. Modules Collections of cmdlets Portable Stored in file system %windir%System32WindowsPoweshell1.0Modules Module Cmdlets: New-Module, Get-Module, Import-Module, Remove-Module Module Manifest Cmdlets: New-ModuleManifest , Test-ModuleManifest
  • 12. Creating Functions function Get-OS { param( [string[]]$ComputerName = $env:COMPUTERNAME ) gwmi Win32_OperatingSystem -ComputerName $ComputerName } PS C:> Get-OS -ComputerName “MyClient1”, ”MyClient2”
  • 13. Creating Modules Modules Location: %windir%System32WindowsPoweshell1.0Modules Create a PS module folder (eg: MyModule) Save PS module with extension .PSM1 instead of .PS1 (MyModule.psm1) • PS module folder name must have same name as PS module file basename
  • 15. Comment Based Help Function Get-OS { <# .SYNOPSIS <toktok> .DESCRIPTION <toktok> .PARAMETER ComputerName <toktok> .EXAMPLE Get-OS .LINK http://mysite.com/get-os/ #> Param ( [string]$ComputerName, [switch]$Details ) }
  • 17. Accepting Pipeline Input function Get-OS { param( [Parameter(ValueFromPipeLine=$true)] [string[]]$ComputerName = $env:COMPUTERNAME ) PROCESS { <blabla> } }
  • 19. Create PS Object $Obj = New-Object –Type PSObject $Obj | Add-Member –Name ComputerName –Value $ComputerName –Type NoteProperty $Obj | Add-Member –Name OS –Value $OS –Type NoteProperty $Obj | Add-Member –Name ServicePack –Value $ServicePack –Type NoteProperty $Obj | Add-Member –Name Version –Value $ComputerName –Type NoteProperty Return PS Object (to pipeline) $Obj
  • 20. Conclusion PowerShell is the future present PowerShell is Self-discoverable  Remember 3 basic commands Reuse code using functions in modules It’s easy - Try it, you’ll see!

Notes de l'éditeur

  1. Check out about_Regular_Expressions