Your SlideShare is downloading. ×
PowerShell Functions
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

PowerShell Functions

761

Published on

Presentation on PowerShell Functions for the Arizona PowerShell User Group June Meeting.

Presentation on PowerShell Functions for the Arizona PowerShell User Group June Meeting.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
761
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PowerShell Functions Presented by Mike Pfeiffer http://www.AZPoSH.com
  • 2. Agenda
    • PowerShell Functions
      • What is a PowerShell Function?
      • Structure of a PowerShell Function
      • Function Guidelines
      • Input Parameters
      • Output
      • Scope
      • Functions in the Pipeline
      • Begin, Process and End Blocks
      • Parameter Attributes
      • Comment Based Help
  • 3. What is a PowerShell Function?
    • Think of it as a block of code that behaves as a cmdlet
    • Can be loaded from your profile, dot sourced via a script, or imported from a module
    • Can be called or defined in another function or script
  • 4. Structure of a PowerShell Function
  • 5. Function Guidelines
    • Must be defined before they are called
    • Call functions without parenthesis or commas:
      • Get-MyStuff –Param1 $value1 –Param2 $value2
      • Get-MyStuff $value1 $value2
  • 6. Input Parameters
    • The $args variable
    • Named and positional parameters
    • Parameter type constraints
    • Initializing parameters with default values
    • The switch parameter
  • 7. Output
    • Write-Host is for writing to the console
    • Use Write-Output to return function output
    • Don’t use the Return keyword to return output
  • 8. Scope
    • Functions have internal scope
    • Don’t use or modify variables from parent scope
    • Consider using default values for internal variables
  • 9. Functions in the Pipeline
    • The $input variable
    • Filters
  • 10. Begin, Process and End Blocks
  • 11. Parameter Attributes Parameter Attribute Declaration (MSDN): http://bit.ly/bzGu34
  • 12. Comment Based Help
  • 13. Resources
    • Get-Help About_Functions
    • Get-Help About_Functions_Advanced
    • Get-Help About_Comment_Based_Help
    • PowerShell in Action
      • http://manning.com/payette2/
    • PowerGUI PowerShell v2 Snippets
      • http://bit.ly/azDkJG
  • 14. Thank You!

×