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 the two strings. This is what I have.
$users = Get-ADUser -Searchbase "OU=test,DC=Whatever,DC=LOC" -filter *
Foreach ($user in $users) {
$homedirectory = (Get-Aduser -Identity $user -properties homedirectory | Select homeDirectory )
$OneDrivePath = "\\test\test\" + (Get-ADUser -Identity $user -properties SAMAccountName | Select SAMAccountname)
$output = New-Object -Typename psobject -Property @{
HomeDirectory = $homedirectory
OneDrivePath = $OneDrivePath
}
}
$output | Select HomeDirectory, OneDrivePath | Export-csv "C:\temp\test.csv"
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"