Skip to content

Instantly share code, notes, and snippets.

@csandfeld
Last active September 6, 2015 15:14
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 csandfeld/77c28a98ca2fe8fcd078 to your computer and use it in GitHub Desktop.
Save csandfeld/77c28a98ca2fe8fcd078 to your computer and use it in GitHub Desktop.
@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