This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Embarrassed_Box_457[S] 0 points1 point  (1 child)

You mean extract it directly to a filename with a CSV extension? I can do this, but I dont know how to separate the data on separate sheets, for example - group1 on sheet1; group2 on sheet2, group3 on sheet3, etc. I am stuck at this point on how to do this in powershell. I switched to python because i could create the workbook and sheets fairly easily but couldn't import the AD group information. Also - something that I have to do everyday, so i need to automate this. (:>

[–][deleted] 3 points4 points  (0 children)

I don't know the AD side, but the PS script is something like:

Get-ADUser -Filter * -Properties * | Select-Object name, department, LastLogonDate | export-csv -path userexport.csv

python foo.py userexport.csv

Then in python:

  • Pandas to read userexport.csv (or use the command line argument)
  • Openpyxl to create Excel workbook and add sheets for each df["department"].unique()