dev-resources.site
for different kinds of informations.
โ Do you allow wrong input to enter your function?
Published at
10/19/2024
Categories
powershell
windows
sysadmin
scripting
Author
kamilpro
Author
8 person written this
kamilpro
open
โ Then stop, PowerShell can help you validate your parameters.
The first picture shows how to manually validate whether the number provided is between 1 and 100. It's not perfect.
The second picture does the same and more with fewer lines of code:
- 1๏ธโฃ Makes the parameter required
- 2๏ธโฃ Ensures the provided number is within 1 and 100
- 3๏ธโฃ The [int] type ensures the $Number parameter is an integer
If any of the checks fails, PowerShell prompts the user for the right data, or errors out.
The wrong input never enters your function - it's like a bouncer at the party!
Follow me for more tips!
powershell Article's
30 articles in total
Windows ไธ VSCode ็ C/C++ ๅปถไผธๆจก็ต่็็ทจ็ขผ็ๅ้ก
read article
PowerShell ็ๆๅญ็ทจ็ขผ
read article
็ฌ่ฎฐ3
read article
TryHackMe | Windows PowerShell | RSCyberTech
read article
Configuring Hyper-V Global Default Directories
read article
How I Set Up an Awesome PowerShell Environment for Script Development
read article
Azure Function App (Flex Consumption) PowerShell Modules solution
read article
File Comparison Made Easy: Detecting New and Changed Files with PowerShell
read article
10 Best Practices of PowerShell Code Signing for Signing Your Script
read article
PowerShell Script Collection: Automation and Solutions for Everyday Tasks
read article
Video: List All Available Windows Features on Windows 11 using CMD & PowerShell
read article
Set up Azure Network Security Perimeter with PowerShell
read article
Automating Azure Project Setup with PowerShell and GitHub Actions
read article
Azure Function App (Flex Consumption) in private VNET via IaC
read article
Using PowerShell to Create Service Principals for RBAC
read article
Two ways to use Pester to Mock objects with strongly typed parameters
read article
PowerShell Automation: Execute Batch GitHub CLI Commands
read article
โ Do you allow wrong input to enter your function?
currently reading
Introducing PowerShell Utility Scripts
read article
Cisco DHCP Pool conversion to Windows Server DHCP
read article
PowerShell | Script output garbled Chinese characters
read article
Rename Multiple Files in Sequence with Just One Click Using PowerShell in Windows! ๐
read article
Redirect Out-File to TestDrive: in your PowerShell Pester test scripts with this one weird trick
read article
Using PowerShell for day to day stuff
read article
Automating SharePoint Embedded: Using PowerShell to Call Graph API Endpoints
read article
Install Ubuntu on WSL 2
read article
How to Install WSL from PowerShell on Windows 10 and 11
read article
How to Run PowerShell Script in Jenkins Pipeline
read article
Identify Which Files are Large.
read article
Quick guide to setting up an shortcut/alias in windows
read article
Featured ones: