Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #writing out the declaration of $names to the screen
- "`$names = `'hamster`'`, `'dance`' "
- $names = 'hamster', 'dance'
- function print-Variable {
- Param(
- [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
- [string[]] $Name
- )
- "Output from Basic Function`n`t--hello $Name"
- "Note that though `$names contains two objects, the main body of the script process only executes one time"
- }
- $names | print-Variable
- function AdvancedPrint-Variable {
- Param(
- [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
- [string[]] $Name
- )
- begin {#Stuff we want to happen once before our process executes goes here
- Write-host -ForegroundColor Yellow "Beginning advanced function"
- }
- process{#Stuff we want to happen for every object in the pipeline goes here
- "Output from Advanced Function`n`t--hello $Name"}
- end {#cleanup operations and stuff we want to happen at the end of our process goes here
- Write-host -ForegroundColor Yellow "Ending advanced function"
- "Now, note that because we have a process block, PowerShell will enumerate our objects for us, and run the main process block once for each object. Also note that the Write-Host commands in the begin and end blocks are only displayed once, even though the process block executes twice (once for each object)"}
- }
- $names| AdvancedPrint-Variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement