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"
TJCooper440
Copper Contributor
Thank you. That worked. How would I add more to this string. I realized the doc needs _contoso_loc to the end. I tried + "_contoso_loc", but its not working
It needs to be \\test\test\(samaccountname)_constoso_loc.
Again, thank you. It helped out tremendously.
$OneDrivePath = "\\test\test\" + (Get-ADUser -Identity $user -properties SAMAccountName | Select-Object SAMAccountname).SamAccountName
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"