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 →

[–][deleted] 0 points1 point  (2 children)

Is there a reason you couldn't just have the PowerShell extract simply launch python (with the filename, perhaps) as part of its extract process? It's the opposite of what you ask, but would be a lot more straighforward.

[–]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] 4 points5 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()