PowerShell Functions
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

PowerShell Functions

on

  • 1,072 views

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

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

Statistics

Views

Total Views
1,072
Views on SlideShare
1,072
Embed Views
0

Actions

Likes
0
Downloads
23
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

PowerShell Functions Presentation 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!