Here is my issue:
I have a function that I pass a parameter too which is actually an IP address. I need to inside the function, compare that parameter to output the portgroup. Here is my function: No matter what parameter I pass, I keep getting this as the output "No portgroup exist"
Function Portgroup{
param($Prod_IP)
If ($Prod_IP -like "10.10.")
{
$Portgroup = "portgroup 10.10.0.0"
}
Elseif ($Prod_IP -like "10.11.")
{
$Portgroup = "portgroup 10.11.0.0"
}
Elseif ($Prod_IP -clike "10.12.")
{
$Portgroup = "portgroup 10.12.0.0"
}
Else
{
$Portgroup = "No portgroup exist"
}
$Portgroup
}
If ($Prod_IP -like "10.10.*")
Or
If ($Prod_IP.StartsWith("10.10."))
---
MCITP: SA+VA, VCP 3/4, VMware vExpert
If ($Prod_IP -like "10.10.*")
Or
If ($Prod_IP.StartsWith("10.10."))
---
MCITP: SA+VA, VCP 3/4, VMware vExpert
With the -like operator you have to add an asterisk as the wildcard.
In the position of the asterisks can be any character any number of times.
Something like this
function Portgroup{ param($Prod_IP) if ($Prod_IP -like "10.10.*") { $Portgroup = "portgroup 10.10.0.0" } elseif ($Prod_IP -like "10.11.*") { $Portgroup = "portgroup 10.11.0.0" } elseif ($Prod_IP -clike "10.12.*") { $Portgroup = "portgroup 10.12.0.0" } else { $Portgroup = "No portgroup exist" } $Portgroup }
PS: why do you use the -clike operator instead of -like ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference