Forum Discussion
TJCooper440
Mar 09, 2022Copper Contributor
Migrating H drives to One Drive - Create csv
I am trying to create a CSV to migrate H drives to one drive. The CSV needs to have the path to the H drive and the SharePoint path to one drive. I am having trouble creating a script that can export...
- Mar 10, 2022
TJCooper440 Ah, no problem. Changed it again, a bit more compact and also using only one Get-Aduser like AndySvints mentioned 🙂
$Users = Get-ADUser -Searchbase "OU=users,OU=Corp,DC=test,DC=local" -Filter * -Properties HomeDirectory, SamAccountName $TotalOutput = @() Foreach ($User in $Users) { $OneDrivePath = "\\test\test\" + $user.SamAccountName + "_constoso_loc" $Output = New-Object -Typename psobject $Output | Add-Member -MemberType NoteProperty -Name HomeDirectory -Value $User.HomeDirectory $Output | Add-Member -MemberType NoteProperty -Name OneDrivePath -Value $OneDrivePath $Totaloutput += $Output } $Totaloutput | Export-csv "C:\temp\test.csv" -NoTypeInformation
Output:"HomeDirectory","OneDrivePath" "\\w2k22dc\home$\test.user1","\\test\test\test.user1_constoso_loc" "\\w2k22dc\home$\test.user2","\\test\test\test.user2_constoso_loc" "\\w2k22dc\home$\test.user3","\\test\test\test.user3_constoso_loc"
AndySvints
Mar 10, 2022Iron Contributor
Hello Harm_Veenstra and TJCooper440,
In addition to Harm's reply I would like to add that instead of running Get-ADUser 3 times you can run it ones(on 1st line), and get all the needed properties(HomeDirectory, SAMAccountName etc.) and then rotate them into PSObject as you needed.
Also I would add user's first and last name to output array just for future reference and convenience.
Hope that helps.
Mar 10, 2022
You're right, I only fixed the output thing but yes.. More efficient like that