I’m doing a Get-ADUser search for inactive/dormant users, including the ‘lastlogon’ attribute for each user (and querying all four domain controllers as I know this attribute doesn’t replicate). This is working fine. (Obviously I have up to four entries for each user, but Security are happy with that - they’ll deal with it).
However, I can’t get the overall output on to a single spreadsheet. I essentially want the output of each DC to ‘append’ to the csv file, rather than overwrite it (tried -NoClobber to prevent any overwrites but I obviously only end up with the output of a single DC).
On my first attempt, I had to use Out-File, write to a text file using the -Append switch. I then pasted that into Excel and messed with it a little to get what I wanted. OK as a one-off, but it looks like I’m going to be asked for this on a regular basis. Also, more properties are now required per user and it’s defaulting to a list-view. I’ve tried format-table before exporting to my text file (which I know isn’t great), but I think it’s time I just found a way of natively exporting everything to a single csv file. I’ve shifted curly braces around and still get errors. I’m sure I’ll kick myself when I find out what’s wrong.
My input file is simply a single-column csv containing the first name and last name of each user. Column header is ‘name’.
Could somebody please look at the attached code and suggest how I might use Export-Csv to a single csv file? (I’ve left the current Out-Default cmdlet at the end for now).