Powershell – how to replace OS Version number with String

Question:

I am querying remote servers for their operating system. I know that I can return the Version, but I want to replace these values with the friendly name. The code I have so far is:

But this doesn’t seem to work and only returns “2003” regardless. Please help, I’m fairly new to PS and coding.

thanks

Answer:

You can use this:


Additionally you can see everything this WMI object holds like this:

Edit: if you want to remove some text from the string, you can use -replace:

Source:

Powershell – how to replace OS Version number with String by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply