Is there a shorter way to write this powershell code? I want to know if there is a better way to query multiple criteria and return the answer at the bottom.
$PC = Read-Host -Prompt 'Give me PC name'
$OSname = $null
$OS = $null
$OS = (get-adcomputer $PC -Properties operatingSystem).OperatingSystem
If ($OS -like "Windows 10*")
{
$OSname = "Win 10"
}
If ($OS -like "*Server 2022*")
{
$OSname = "Win 2022"
}
If ($OS -like "*Server 2019*")
{
$OSname = "Win 2019"
}
If ($OS -like "*Server 2016*")
{
$OSname = "Win 2016"
}
If ($OS -like "*Server 2012*")
{
$OSname = "Win 2012"
}
If ($OS -like "Windows 7*")
{
$OSname = "Win 7"
}
If ($OS -like "*Server 2008*")
{
$OSname = "Win 2008"
}
If ($OS -eq $null)
{
$OSname = "NO OS"
}
$Osname