Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

Powershell: Check is a valid IP address

To check if a string represents a valid IP address in PowerShell, you can use the System.Net.IPAddress class. Here’s an example:

$ipAddressString = ""

$isValidIP = [System.Net.IPAddress]::TryParse($ipAddressString, [ref]$null)

if ($isValidIP) {
    Write-Host "The IP address '$ipAddressString' is valid."
else {
    Write-Host "The IP address '$ipAddressString' is not valid."

In this script, we assign the IP address string to the $ipAddressString variable. We then use the TryParse method of the System.Net.IPAddress class to attempt parsing the string as an IP address. The method returns a boolean value indicating whether the parsing was successful.

If the IP address string is valid, the script displays a message confirming its validity. Otherwise, it shows a message indicating that the IP address is not valid.

You can replace the $ipAddressString variable with the IP address string you want to check. Feel free to integrate this IP address validation logic into your existing scripts or modify it as per your specific requirements.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments