Forum Discussion

TJCooper440's avatar
TJCooper440
Copper Contributor
Mar 09, 2022

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...
  • Harm_Veenstra's avatar
    Harm_Veenstra
    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"

     

     

     

Resources