<\/use><\/svg><\/div><\/a><\/div>Of course if I succeed they’ll want … more like each location on a separate tab, or at least a spacer line… <\/p>","upvoteCount":0,"datePublished":"2018-03-22T17:54:01.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/6","author":{"@type":"Person","name":"bob-13","url":"https://community.spiceworks.com/u/bob-13"}},{"@type":"Answer","text":"How come ‘joe’ is ok to be listed twice?<\/p>\n
Or Smith?<\/p>\n
Is that just needed for he first columns?<\/p>","upvoteCount":0,"datePublished":"2018-03-22T17:55:18.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
They need “full user” info, but the common stuff, like location and Dept. should be grouped… and then it is easier to tell when it changes if the repeats aren’t there.<\/p>\n
If the same “Joe Smith” had an office in Edmonton and Calgary they’d probably want me to show that somehow… but that should never happen.<\/p>\n
Edit:<\/p>\n
Seriously, the report as is should be just fine, they just want to make it… pretty. I want to say “it is pretty… pretty functional.”<\/p>","upvoteCount":0,"datePublished":"2018-03-22T18:00:29.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/8","author":{"@type":"Person","name":"bob-13","url":"https://community.spiceworks.com/u/bob-13"}},{"@type":"Answer","text":"
I see now. Your best bet is to import this data into Microsoft Access, which has an import wizard. Then, run the report wizard which, if memory serves, has a ready-made template that does exactly this. The wizard gives you a preview so you can see exactly what it is going to do. You can even have it do the sorting for you.<\/p>","upvoteCount":1,"datePublished":"2018-03-22T18:26:52.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/9","author":{"@type":"Person","name":"kevin-systemtools-software","url":"https://community.spiceworks.com/u/kevin-systemtools-software"}},{"@type":"Answer","text":"
Like so?<\/p>\n
$data = import-csv $env:userprofile\\desktop\\input.csv\n$data | ft *\n\nforeach ($column in ($data | get-member | where membertype -eq 'noteproperty' | sort -Descending).name) {\n if (-not($column -eq 'LastName' -or $column -eq 'FirstName')) {\n foreach ($row in 1..($data.count - 1)) {\n if ($data[$row].$column -eq $data[$row - 1].$column -or $data[$row].$column -eq $data[$row - 2].$column) {\n $data[$row].$column = \" \"\n }\n }\n }\n}\n\n$data | ft *\n<\/code><\/pre>\n <\/p>\n
<\/p>","upvoteCount":1,"datePublished":"2018-03-22T19:55:29.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\nLike so?<\/p>\n
$data = import-csv $env:userprofile\\desktop\\input.csv\n$data | ft *\n\nforeach ($column in ($data | get-member | where membertype -eq 'noteproperty' | sort -Descending).name) {\n if (-not($column -eq 'LastName' -or $column -eq 'FirstName')) {\n foreach ($row in 1..($data.count - 1)) {\n if ($data[$row].$column -eq $data[$row - 1].$column -or $data[$row].$column -eq $data[$row - 2].$column) {\n $data[$row].$column = \" \"\n }\n }\n }\n}\n\n$data | ft *\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nI suspect… not. <\/p>\n
That would work with the data I used in the demo, but the SQL Query that creates the Data to export to CSV is more complex… there could be many rows with 1 value so the “Row-1” and “row -2” would need some kind of… loop to find the last row where that column had a value.<\/p>\n
However these replies have confirmed my suspicions that this isn’t simple. The SQL query does all the sorting, and grouping, but the “erase redundant” values in columns… is the part I haven’t done.<\/p>\n
(Query has 8 columns the first 4 would need “cleanup” the last 4 wouldn’t and an example of it has only 1 value in column 1 and 72 rows… so I’d be expected to remove 71 of them, the second column has… 3 values and an uneven split… etc.)<\/p>\n
I’ll just say… “you want it to work or look nice before<\/em> you get it?” I mean really… they can’t hit the delete key themselves?<\/p>","upvoteCount":0,"datePublished":"2018-03-22T20:48:48.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/11","author":{"@type":"Person","name":"bob-13","url":"https://community.spiceworks.com/u/bob-13"}},{"@type":"Answer","text":"How come they can’t do the sorting and such in SQL.<\/p>\n
SQL is better for that compared to PowerShell in theory<\/p>","upvoteCount":0,"datePublished":"2018-03-22T20:51:20.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/12","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\nHow come they can’t do the sorting and such in SQL.<\/p>\n
SQL is better for that compared to PowerShell in theory<\/p>\n<\/blockquote>\n<\/aside>\n
The sot is done in sql, But either I don’t know the syntax, or every record includes the data, and no blank spaces.<\/p>\n
I suppose I could go the the SQL forum and ask for help. <\/p>","upvoteCount":0,"datePublished":"2018-03-22T20:59:44.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/13","author":{"@type":"Person","name":"bob-13","url":"https://community.spiceworks.com/u/bob-13"}},{"@type":"Answer","text":"
Could it be done? Probably.<\/p>\n
Is there a point? Not really.<\/p>\n
Information is being thrown away. So the report cannot realistically be manipulated any further. Like sorting in Excel by department or location or whatever. Or additional grouping and sorting.<\/p>\n
Making it ‘pretty’ (very subjective) is probably not worth the effort in powershell.<\/p>\n
Perhaps the output from SQL using GROUP BY, HAVING, ORDER BY and other SQL commands would be enough. Takes a little effort and I’ve forgotten most of it at this point.<\/p>","upvoteCount":0,"datePublished":"2018-03-22T23:34:45.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/14","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"\n\n
<\/div>\n
M Boyle:<\/div>\n
\nCould it be done? Probably.<\/p>\n
Is there a point? Not really.<\/p>\n
Information is being thrown away. So the report cannot realistically be manipulated any further.<\/em> Like sorting in Excel by department or location or whatever. Or additional grouping and sorting.<\/p>\nMaking it ‘pretty’ (very subjective) is probably not worth the effort in powershell.<\/p>\n
Perhaps the output from SQL using GROUP BY, HAVING, ORDER BY and other SQL commands would be enough. Takes a little effort and I’ve forgotten most of it at this point.<\/p>\n<\/blockquote>\n<\/aside>\n
Cannot manipulate further? I’m not sure I agree with that, but, I understand where you are coming from.<\/p>\n
The SQL clause is already one of the “more complex” I’ve done in years. It includes group by and order by clauses, and multiple tables and where conditions etc. so… I fully believe there is little point in these “readability touch-ups” when the data is there… and if you don’t like it you can delete it yourself, (Or hide it, etc.)<\/p>","upvoteCount":0,"datePublished":"2018-03-23T12:17:18.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/15","author":{"@type":"Person","name":"bob-13","url":"https://community.spiceworks.com/u/bob-13"}},{"@type":"Answer","text":"
\nCannot manipulate further? I’m not sure I agree with that, but, I understand where you are coming from.<\/p>\n
The SQL clause is already one of the “more complex” I’ve done in years. It includes group by and order by clauses, and multiple tables and where conditions etc. so… I fully believe there is little point in these “readability touch-ups” when the data is there… and if you don’t like it you can delete it yourself, (Or hide it, etc.)<\/p>\n<\/blockquote>\n
I was referring to the lost data in your ‘after’ example. The end user cannot fire up the excel data tools and sort things by dept (as an example) without then losing the ability to resort it by location. Well they can but the data will now be in entirely the wrong order/<\/p>\n
And that’s probably the best reason to say no to the end users. The data output in its current form is “general purpose”.<\/p>\n
They can use the data tools to further manipulate it as they need to or delete data to format it as they’d like to see it and they have to data available to use if they come up with some other great idea in future.<\/p>","upvoteCount":0,"datePublished":"2018-03-23T13:04:16.000Z","url":"https://community.spiceworks.com/t/can-we-make-it-pretty-export-csv-formatting/642008/16","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}}]}}
Neally
(Neally)
March 22, 2018, 3:13pm
4
BrowncoatSGT:
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…
if ($newlocation=$oldlocation){<#stuff#>}
This does not work as ‘=’ is value assignment, not compare, it should be ‘-eq’
@browncoatsgt