Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
Powershell Switch-Statement doesn't change value

This is the Powershell script I wrote:

$varCompList = Get-ADComputer -Filter "Name -like '*Name of Computers*'" -Properties OperatingSystemVersion | select DNSHostName, OperatingSystemVersion
foreach ($System in $varCompList){
    $Restult=switch ($System.OperatingSystemVersion){
        "10.0 (20348)"{"Server 2022"}
        "10.0 (19042)"{"Server 2019 20H2"}
        "10.0 (18363)"{"Server 2019 1909"}
        "10.0 (17763)"{"Server 2019 1809"}
        "10.0 (14393)"{"Server 2016"}
    }
}
echo $varCompList

It displays all the Servers like it should but the OperatingSystemVersion is still displayed as 10.0 (14393).

What am I missing?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You're currently assigning the mapped OS names to a variable, but you never use it for anything and you never update the original input object.

Instead of assigning the result to a variable, assign it to the OperatingSystemVersion property on each object instead:

foreach ($System in $varCompList){
    $System.OperatingSystemVersion = switch ($System.OperatingSystemVersion){
        "10.0 (20348)"{"Server 2022"}
        "10.0 (19042)"{"Server 2019 20H2"}
        "10.0 (18363)"{"Server 2019 1909"}
        "10.0 (17763)"{"Server 2019 1809"}
        "10.0 (14393)"{"Server 2016"}
        default { $_ }
    }
}

The default case will ensure you preserve the original version string for any computer that doesn't have any of the listed versions installed.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda