Skip to content

Instantly share code, notes, and snippets.

@MVKozlov
Last active September 14, 2015 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MVKozlov/b3839c5b060954ad5a2d to your computer and use it in GitHub Desktop.
Save MVKozlov/b3839c5b060954ad5a2d to your computer and use it in GitHub Desktop.
2015-September Scripting Games Puzzle
# --- Why not $OriginalObject | Add-Member ---
# By the challenge "The contents of that column are either computer host names or IP addresses"
# If I use Add-Member, then object can still contain ipaddresses, but not actual hostnames
# I think we are real life admins, and we need actual information :) and in output.csv we get actual host names, not host/ip mix
#No Curly brackets, rename headers by type conversion
(Import-CSV Input.csv).MachineName | Get-CimInstance -ClassName Win32_OperatingSystem | Select PSComputerName, Caption | ConvertTo-CliXml) -replace '<S N="PSComputerName">','<S N="MACHINENAME">' -replace '<S N="Caption">','<S N="OSVERSION">' | ConvertFrom-CliXml | Export-CSV Output.csv -NoTypeInformation -Encoding Utf8
#Final variant:
#No Semicolons, No any brackets at all, No any quotations, No extra conversions. Just for fun :)
Import-CSV Input.csv | Select-Object -Expand MachineName | Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property PSComputerName, Caption | Add-Member -PassThru -MemberType AliasProperty -Name OSVERSION -Value Caption | Add-Member -PassThru -MemberType AliasProperty -Name MACHINENAME -Value PSComputerName | Select-Object MACHINENAME, OSVERSION | Export-Csv -NoTypeInformation Output.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment