Output data into multiple files [SOLVED]

by rvuppuluri at 2012-11-01 22:40:44


Firstly, thank you ADMINS for creating such a forum which helps a noob, in powershell scripting, like me on a day to day basis.

Now coming to my question:

Below is a script I am using to pull the Users and their information from the Active Directory,

[quote]Get-QADUser -Activity “Getting Users - Please Wait” -IncludedProperties employeeID,employeeType | Select SamAccountName, DN, employeeType, employeeID, ParentContainerDN | Export-Csv OutputData.csv -notype[/quote]

The AD I am connecting to has over 60000 Users. Now I want to be able to split this data into multiple csv files [Say, 10000 user records per file. That makes the number of output files to be 6] for the logistical purposes in my company.

Is there a code I can use to plug into my existing code to get the Users and output/Export the data into multiple files?


Also helpful would be if you can help me with appending a date/time stamp to these output files. Eg: OutputData_1_11022012.csv

PS: The above code is utilizing the Quest Active Management Shell cmdlets and I think it is safe for me to say that Powershell and Quest Powershell almost function the same way, with the differences in the cmdlets they provide.

Any help would be greatly appreciated.

by DonJ at 2012-11-02 08:29:18
No, Export-CSV only outputs to one file. What you’d need to do is run the command several times, perhaps, each time pulling back only a subset of users. Rather than arbitrarily breaking them up in chunks of 10,000, it would probably make sense to group them by, say, organizational unit or something. But whatever works for you.

You can use Get-Date to retrieve the current date, and that object has methods that would let you pull out a string timestamp like you want.
by rvuppuluri at 2012-11-04 22:25:00

Thank you for your response.

I have modified my code to the following:
$ObjCount=Get-QADUser|Measure-Object|Select Count


for($i=1; $i -le 6; $i++)
Get-QADUser -pagesize $ObjCount_Rounded -Activity “Getting Users - Please Wait” -IncludedProperties employeeID,employeeType | Select SamAccountName | Export-csv UserData_$i.csv -notype

Just when I thought I had it all the ‘-PageSize’ switch does not look like its working. I get 6 files with each file containing the complete list of users, and not split. Any insight? Appreciate your help.

by rvuppuluri at 2012-11-05 02:16:56
So I was able to finally crack this:

For benefit of others who are viewing this thread I would like to share how I did this. I have used a csv file which takes properties like number of file outputs, folderpaths etc. I imported that data and here is the code:

$FileSplitNum=Import-Csv PropertyFile.csv | Select SplitFileNum | Select -index 0
$FolderPath=Import-Csv PropertyFile.csv | Select FolderPath | Select -index 0


$UserDataVar=Get-QADUser -Activity “Getting Users - Please Wait” -IncludedProperties employeeID,employeeType | Select SamAccountName, DN, employeeType, employeeID, ParentContainerDN

for($i=1; $i -le $FileSplitNum.SplitFileNum;$i++)

for($j=1; $j -le $ObjCount_Rounded; $j++)
$UserDataVar[($x*$ObjCount_Rounded)+$j] | Export-csv $DataExportLocation""$i""$(get-date -f yyyy-MM-dd).csv -append -notype

Thank you.