Tag Archives: Office365

Reverse engineering email address from OneDrive personal site Url

Sup’ PSHomies,

Migrations… Gotta love ’em!!!

I’m doing a OneDrive for Business tenant to tenant migration using Sharegate. If you ever decide to do any sort of SharePoint affiliated migration, best to use Sharegate! Their support is top notch! Shout out to Jimmy De Santis!

Sharegate has a cmdlet Get-OneDriveUrl that will retrieve or provision you ODFB URL (OneDrive For Business). Depending on a user’s Primary SMTP Address the URL format may not be what you expected.

Here’s a link to the script to get your ODFB information of your organization.  Be sure to follow the setup instructions.

This will generate a simple text file (I used it as-is, a rare occasion, I know… Don’t judge me…). To generate the URL, you need to swap any ‘.’ and ‘@’ for ‘_’.  I’m looking to reverse this process. Why? Well because I hate manual work. I’m almost certain I have to do this again sometime in the near future…

Those who forget to automate are doomed to repeat their work…

Words to live by…

My hunch paid off! By reverse engineering the email address from the ODFB URL, I could use that email address to retrieve the ODFB URL using Get-OneDriveUrl. I needed to provision the URLs in the target domain, fortunately the email addresses in the Target tenant are uniform.

Ok here’s the code:

$personalSites = @"
personalSite
/personal/a_v_d_hoogt_simba_nl/
/personal/h_altafah_simba_nl/
/personal/c_v_d_meulen_simba_nl/
/personal/stand_simba_nl/
/personal/floortje_janssen_simba_nl/
/personal/j_dubendorffer_sudoku_nl/
/personal/m_d_haas_sudoku_nl/
/personal/j_slimmer_sudoku_nl/
/personal/m_rijs_sudoku_nl/
/personal/b_janssen_despacito_com/
/personal/m_pools_despacito_com/
/personal/r_stewardess_despacito_com/
/personal/t_koestsier_despacito_com/
"@ | ConvertFrom-Csv
$personalSites |
ForEach-Object {
#Get ODFB part
Try {
$arrODFBUrl = ($($_.personalSite).Split('//'))[-2].Split('_')
$count = @($arrODFBUrl).Count
$index = 1
$emailUsedForODFB = $arrODFBUrl[0]
Do {
if ($arrODFBUrl[$index] -like 'despacito*') {
$emailUsedForODFB = "$($emailUsedForODFB)@$($arrODFBUrl[$index])"
}
elseif ($arrODFBUrl[$index] -like 'simba*') {
$emailUsedForODFB = "$($emailUsedForODFB)@$($arrODFBUrl[$index])"
}
elseif ($arrODFBUrl[$index] -like 'sudoku*') {
$emailUsedForODFB = "$($emailUsedForODFB)@$($arrODFBUrl[$index])"
}
else {
$emailUsedForODFB = "$($emailUsedForODFB).$($arrODFBUrl[$index])"
}
$index++
}until($index -eq $count)
#Some ODFB may have a '1' at the end. Just remove that
if ($emailUsedForODFB -like '*nl1') {
$emailUsedForODFB = $emailUsedForODFB -replace ".$"
}
$samAccountName = $emailUsedForODFB.Split('@')[0].ToLower()
$targetEmail = '{0}@urv.onmicrosoft.com' -f $samAccountName
[PSCustomObject]@{
SamAccountName = $samAccountName
SourceEmail = $emailUsedForODFB
SourcePersonalUrl = $($_.personalSite)
SourceGeneratedUrl = 'https://irwins-my.sharepoint.com/personal/{0}/' -f $emailUsedForODFB.Replace('@', '_').Replace('.','_').ToLower()
TargetEmail = $targetEmail
TargetGeneratedUrl = 'https://urv-my.sharepoint.com/personal/{0}/' -f $targetEmail.Replace('@', '_').Replace('.','_').ToLower()
}
}
catch {
Write-Warning 'Not a valid personal site format'
}
} |
Out-GridView

Having the email address I can generate the source URL and verify if it is what I expected it to be. The samaccountname remained the same, so it was easy enough to generate the new email address and the expected target URL which once I provision, can also be verified that it is what I expected it to be. Still with me? Just have a look at the image… 😉

Generated ODFB Urls

You can generate quite the information by just have a personal ODFB Url!

Not being content with just the generated information, I did one last check using Sharegate’s Get-OneDriveUrl:

$csvUrls = Import-Csv C:\scripts\sources\csv\VerifyUrls.csv -Delimiter "`t" -Encoding UTF8
#region Initialize Stuff
Import-Module ShareGate -Verbose:$false
# User account for an Office 365 global admin in your organization
# https://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell/
$HashCreds = Import-CliXml -Path "${env:\userprofile}\Hash.Cred"
#Admin urls
$targetAdminUrl = 'https://urv-admin.sharepoint.com'
$sourceAdminUrl = 'https://irwins-admin.sharepoint.com'
#Connect to Tenant Site
$targetTenantSite = Connect-Site -Url $targetAdminUrl -Credential $HashCreds.'urv-target-o365admin'
$sourceTenantSite = Connect-Site -Url $sourceAdminUrl -Credential $HashCreds.'irwins-source-o365admin'
Function Get-ODFBUrls{
param($sourceUserEmail,$targetUserEmail)
#Provision using Sharegate and wait for it to finish.
$targetOneDriveUrl = Get-OneDriveUrl -Tenant $targetTenantSite -Email $targetUserEmail
$sourceOneDriveUrl = Get-OneDriveUrl -Tenant $sourceTenantSite -Email $sourceUserEmail
[PSCustomObject]@{
SourceEmail = $sourceUserEmail
SourceODFBUrl = $sourceOneDriveUrl
TargetEmail = $targetUserEmail
TargetODFBUrl = $targetOneDriveUrl
}
}
#region Get ODFB Urls
$csvUrls |
ForEach-Object{
Get-ODFBUrls -sourceUserEmail $_.SourceEmail -targetUserEmail $_.TargetEmail
}|
Export-Csv C:\scripts\export\ODFBUrls-27112017.csv -Encoding UTF8 -Delimiter "`t" -NoTypeInformation
#endregion

This aligns the source and target URLs nicely! Now I can migrate from tenant to tenant without to much hassle… Well at least that’s the plan… 😉

Hope it’s worth something to you,

Ttyl,

Urv