Building Dynamic Parameters into your PowerShell Code

Building Dynamic Parameters into your PowerShell Code
In this video, PowerShell instructor Jason Yoder explains how you can add parameters into you PowerShell code. He also explains how parameters can turn your existing static code into a more dynamic scripting tool.
For instructor-led PowerShell training by Jason Yoder, see our course schedule.
Dynamic Parameters in PowerShell used in this video.
Download the DynamicParameters-in-PowerShell code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | <# ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ How to Code for Parameter Use ║ ╟──────────────────────────────────────────────────────────────────────────────╢ ║ Interface Technical Training ║ ║ Jason A Yoder ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════════════╝ #> # Notice the available parameters of Get-Date Get-Date # Create a very basic function with a basic parameter. Function Test-ParameterCode { Param ($String1) Write-Host $String1 -BackgroundColor DarkGreen } # Test the function Test-ParameterCode -String1 "Jason" # Create multiple parameters Function Test-ParameterCode { Param ($String1, $Number) For ($X = 1 ; $X -le $Number ; $X++) {Write-Host $String1 -BackgroundColor DarkGreen} } # Test the function Test-ParameterCode -String1 Hello -Number 3 # Look at the help file. Get-Help Test-ParameterCode Function Test-ParameterCode { Param ( [String]$String1, [Int] $Number ) For ($X = 1 ; $X -le $Number ; $X++) {Write-Host $String1 -BackgroundColor DarkGreen} } # Look at the help file. Get-Help Test-ParameterCode # Create default values Function Test-ParameterCode { Param ( [String]$String1 = "Hello World", [Int] $Number = 5 ) For ($X = 1 ; $X -le $Number ; $X++) {Write-Host $String1 -BackgroundColor DarkGreen} } # Test the function Test-ParameterCode Test-ParameterCode -Number 2 # Learn more about Parameters Get-Help about_Parameters -ShowWindow |
You May Also Like
A Simple Introduction to Cisco CML2
0 3774 0Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2
How to Build in a PSMethod to your PowerShell Code
0 71 0In this video, PowerShell instructor Jason Yoder shows how to add Methods (PSMethod) to your code using free software that’s added into the PSObject. For instructor-led PowerShell courses, see our course schedule. Microsoft Windows PowerShell Training Download the Building Methods PowerShell script</a> used in this video. <# ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ Building Methods ║ ╟──────────────────────────────────────────────────────────────────────────────╢ … Continue reading How to Build in a PSMethod to your PowerShell Code
How to use the PowerShell Script Analyzer to Clean Up Your Code
0 1235 2In this video, PowerShell instructor Jason Yoder demonstrates how you can use the PowerShell Script Analyzer to help you format your code to best-practices. For instructor-led PowerShell training classes, see our course schedule: Microsoft Windows PowerShell Training Download the PowerShell Analyzer scripts used in this video. <# ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ PowerShell Script Analyzer ║ … Continue reading How to use the PowerShell Script Analyzer to Clean Up Your Code