Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Test-ValidIp($ipaddress)
- {
- try {
- [System.Net.IPAddress]::Parse($ipaddress) | Out-Null
- return $true;
- }
- catch {
- return $false;
- }
- }
- function Use-IpAddress
- {
- Param
- (
- [parameter(Mandatory=$true,
- HelpMessage="Enter an IP Address")]
- [ValidateScript({Test-ValidIp $_})]
- [String]
- $IpAddress
- )
- # Work with $ipaddress here
- }
- # Works fine
- Use-IpAddress -IpAddress "192.168.1.3"
- # Prompts for IPAddress
- Use-IPAddress
- # Throws Error
- Use-IpAddress -IpAddress "garbage"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement