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 3955 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
Creating Dynamic DNS in Network Environments
0 649 1This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader teaches how to create Dynamic DNS zones in Network Environments. Video Transcription: Now that we’ve installed DNS, we’ve created our DNS zones, the next step is now, how do we produce those … Continue reading Creating Dynamic DNS in Network Environments
Cable Testers and How to Use them in Network Environments
0 753 1This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader demonstrates how to use cable testers in network environments. Let’s look at some tools that we can use to test our different cables in our environment. Cable Testers Properly Wired Connectivity … Continue reading Cable Testers and How to Use them in Network Environments