Author Posts

January 1, 2012 at 12:00 am

by jhaighsy at 2012-10-30 06:04:02

Hi, I've created a script which pulls User details from AD and puts them in a csv file. I want to auto run this script every month so to do this I have created a task schedule to run a batch file of the powershell script.

The problem I have is that the csv file is being overwritten each time the script runs. I want it so that a new csv file is created each time and named differently.

I'm new to all of this so not sure where to go with it.

My script is:

Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADUser -SizeLimit 0 | Select-Object lastname,firstname,email | Export-Csv c:\PSexport\Allusers.csv -NoTypeInformation

Any ideas?

by iHunger at 2012-10-30 06:16:28

$today = Get-Date -Format ymmdd
Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADUser -SizeLimit 0 | Select-Object lastname,firstname,email | Export-Csv c:\PSexport\Allusers$today.csv -NoTypeInformation

by jhaighsy at 2012-10-30 06:23:10

Thanks very much for that! Works a treat 🙂