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
Agile Methodology in Project Management
0 184 0In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management
An Overview of Office 365 – Administration Portal and Admin Center
0 950 3This is part 1 of our 5-part Office 365 free training course. In this Office 365 training video, instructor Spike Xavier introduces some of the most popular services found in Microsoft Office 365 including the Admin Portal and Admin Center. For instructor-led Office 365 training classes, see our course schedule: Spike Xavier SharePoint Instructor – … Continue reading An Overview of Office 365 – Administration Portal and Admin Center
Creating Users and Managing Passwords in Microsoft Office 365
0 795 4In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365. For instructor-led Office 365 training classes, see our course schedulle: Spike Xavier SharePoint Instructor – Interface Technical Training Phoenix, AZ 20347: Enabling and Managing Office 365