-
-
Save MVKozlov/b3839c5b060954ad5a2d to your computer and use it in GitHub Desktop.
2015-September Scripting Games Puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- 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