Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
The Power Of PowerShell: Advanced   Kurt Roggen, Technical Consultant,   Devoteamkurt.roggen@devoteam.be
Agenda • PowerShell Basics  •   PS Syntax  •   Pipeline  •   3 cmdlets to know/remember • PowerShell Advanced  •   Functio...
PS Cmdlet Syntax  verb-<ID>SingularNoun   Get-Service, New-Mailbox, Get-ADUser, Get-Disk, Get-VM,   Start-Process, Stop-Pr...
3 cmdlets to know/remember!!PowerShell is self-discoverable using1. Get-Command2. Get-Help3. Get-Member
1. Get-Help Displays help information Get-Help Get-Help get-service Get-Help get-service -examples Get-Help get-service -d...
2. Get-CommandDisplays all commands (cmdlet, function, alias)Get-CommandGet-Command -verb getGet-Command -noun serviceGet-...
3. Get-MemberDisplays all MemberTypes (Property,Methods,...)Get-Service | Get-MemberGet-Member –InputType (Get-Service)Get...
Modules
ModulesCollections of cmdletsPortableStored in file system  %windir%System32WindowsPoweshell1.0ModulesModule Cmdlets: New-...
Functions
Creating Functions function Get-OS{    param(     [string[]]$ComputerName = $env:COMPUTERNAME    )      gwmi Win32_Operati...
Creating ModulesModules Location:%windir%System32WindowsPoweshell1.0ModulesCreate a PS module folder (eg: MyModule)Save PS...
Comment Based Help
Comment Based Help Function Get-OS {  <# .SYNOPSIS           <toktok> .DESCRIPTION       <toktok> .PARAMETER ComputerName ...
Accepting Pipeline Input
Accepting Pipeline Input function Get-OS {     param(       [Parameter(ValueFromPipeLine=$true)]       [string[]]$Computer...
Creating PS Objects
Create PS Object$Obj = New-Object –Type PSObject$Obj   |   Add-Member   –Name   ComputerName   –Value   $ComputerName   –T...
ConclusionPowerShell is the future presentPowerShell is Self-discoverable Remember 3 basic commandsReuse code using funct...
The Power of PowerShell: Advanced
The Power of PowerShell: Advanced
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
Seminar meningitis
Next
Download to read offline and view in fullscreen.

0

Share

Download to read offline

The Power of PowerShell: Advanced

Download to read offline

More info on http://techdays.be.

  • Be the first to like this

The Power of PowerShell: Advanced

  1. 1. The Power Of PowerShell: Advanced Kurt Roggen, Technical Consultant, Devoteamkurt.roggen@devoteam.be
  2. 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. 3. PS Cmdlet Syntax verb-<ID>SingularNoun Get-Service, New-Mailbox, Get-ADUser, Get-Disk, Get-VM, Start-Process, Stop-Process, New-NALun, Get-AzureVM, ...
  4. 4. 3 cmdlets to know/remember!!PowerShell is self-discoverable using1. Get-Command2. Get-Help3. Get-Member
  5. 5. 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
  6. 6. 2. Get-CommandDisplays all commands (cmdlet, function, alias)Get-CommandGet-Command -verb getGet-Command -noun serviceGet-Command -module ActiveDirectoryGet-Command -CmdType cmdletAlias: gcm
  7. 7. 3. Get-MemberDisplays all MemberTypes (Property,Methods,...)Get-Service | Get-MemberGet-Member –InputType (Get-Service)Get-Member –MemberType MethodGet-Member –MemberType PropertyAlias: gm
  8. 8. Modules
  9. 9. ModulesCollections of cmdletsPortableStored in file system %windir%System32WindowsPoweshell1.0ModulesModule Cmdlets: New-Module, Get-Module, Import-Module, Remove-ModuleModule Manifest Cmdlets: New-ModuleManifest , Test-ModuleManifest
  10. 10. Functions
  11. 11. Creating Functions function Get-OS{ param( [string[]]$ComputerName = $env:COMPUTERNAME ) gwmi Win32_OperatingSystem -ComputerName $ComputerName} PS C:> Get-OS -ComputerName “MyClient1”, ”MyClient2”
  12. 12. Creating ModulesModules Location:%windir%System32WindowsPoweshell1.0ModulesCreate 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
  13. 13. Comment Based Help
  14. 14. 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 ) }
  15. 15. Accepting Pipeline Input
  16. 16. Accepting Pipeline Input function Get-OS { param( [Parameter(ValueFromPipeLine=$true)] [string[]]$ComputerName = $env:COMPUTERNAME ) PROCESS { <blabla> } }
  17. 17. Creating PS Objects
  18. 18. 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 NotePropertyReturn PS Object (to pipeline)$Obj
  19. 19. ConclusionPowerShell is the future presentPowerShell is Self-discoverable Remember 3 basic commandsReuse code using functions in modulesIt’s easy - Try it, you’ll see!

More info on http://techdays.be.

Views

Total views

1,849

On Slideshare

0

From embeds

0

Number of embeds

1

Actions

Downloads

73

Shares

0

Comments

0

Likes

0

×