I have Powershell version 3,4 and 5 in my environment. When I write below code it continuously gave me false, though $CompatibleOS contains output of $OSversions.
[string] $CompatibleOS = '2016','2012','2008'
$OSVersion=[regex]::Matches(((Get-WmiObject -class Win32_OperatingSystem).caption), "([0-9]{4})")
if ( $CompatibleOS -contains $OSVersion)
{
return $TRUE
}
else
{
return $FALSE
}
but when I changed above code to below, it worked. What could be the issue?
[string] $CompatibleOS = '2016','2012','2008'
$OSVersion=[regex]::Matches(((Get-WmiObject -class Win32_OperatingSystem).caption), "([0-9]{4})")
if ( $CompatibleOS.contains($OSVersion))
{
return $TRUE
}
else
{
return $FALSE
}