Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@csandfeld 2015 - September Scripting Games Puzzle
# No semicolons, only one set of curlies, using aliases etc. to keep it as short as possible
ipcsv I*|%{$_|Add-Member OSVERSION (gwmi -CN $_.MACHINENAME Win32_OperatingSystem).Caption -P}|epcsv Output.csv
# Same as the above, but longer as I am not taking shortcuts with aliases and an incomplete filename
Import-Csv Input.csv | %{ $_ | Add-Member OSVERSION (Get-WmiObject -ComputerName $_.MACHINENAME Win32_OperatingSystem).Caption -PassThru } | Export-Csv Output.csv
# How I would have done it, had there been no limitations on lenght, semicolons
# and curlies. Better readability, adhearing to culture (I'm danish, so apps
# like Excel expect a semicolon as delimiter in a CSV file) and not outputting
# type information (normaly just get's in the way when using the CSV in another
# app)
Import-Csv -Path Input.csv | Select-Object -Property MACHINENAME, @{ l = 'OSVERSION' ; e = { Get-WmiObject -ComputerName $_.MACHINENAME -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption } } | Export-Csv -Path Output.csv -UseCulture -NoTypeInformation
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
MACHINENAME
localhost
127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment