Archives for posts with tag: script

Hard Match Multiple Office 365 Accounts

1. Save the following as a Get-ImmutableID.PS1 script

###########################################################################################################StartScript###############################################################################################################
[System.Console]::ForegroundColor = [System.ConsoleColor]::White
clear-host
Import-module activedirectory

write-host
write-host This Script will Get the ObjectGUID for a user and convert
write-host it to the Immutuable ID for use in Office 365
Write-Host
write-host Please choose one of the following:
write-host
write-host ‘1) Get ID for a Single User’
write-host ‘2) Get IDs for all Users’
write-host ‘3) Cancel’ -ForegroundColor Red
write-host
$option = Read-Host “Select an option [1-3]”

switch ($option)
{
‘1’{
write-verbose “Option 1 selected”
$GetUser = Read-Host -Prompt ‘Enter UserName’
$Users = get-aduser $GetUser | select userprincipalname,@{label=”ImmutableID”;expression={[System.Convert]::ToBase64String($_.objectguid.ToByteArray())}}
$Users
}

‘2’{
Write-host
Write-host Type the Path location to Export the results: i.e. c:\service\IMID.csv

$Path = Read-Host -Prompt ‘Enter Path’

$Users = get-aduser -filter * | select userprincipalname,@{label=”ImmutableID”;expression={[System.Convert]::ToBase64String($_.objectguid.ToByteArray())}}
$users
$users | export-csv $Path

}
‘3’{
write-verbose “Option 3 selected”
break
}
}

###########################################################################################################EndScript################################################################################################################
2. Select your option

3. Save the CSV file to a directory i.e. C:\Service\IMID.csv

4. Open the CSV file and remove whatever UPN’s and IMID’s that you don’t want to change. Also replace all the “@domain.local” with “@domain.onmicrosoft.com” and save the file

5. Save the following as Set-IMID.ps1

###########################################################################################################StartScript###############################################################################################################

$users = import-csv “C:\Service\IMID.csv”
ForEach ($item in $users)

{
$UPN = $item.(“UserPrincipalName”)

$IMID = $item.(“ImmutableID”)

“Set-MsolUser -UserPrincipalName $UPN -ImmutableId $IMID”
}

###########################################################################################################EndScript################################################################################################################

6. Connect to Office 365 via Powershell

7. Change directory to the location of set-IMID.PS1

8. Type .\Set-IMID.PS1

9. It will print out all the results for you. Copy and and paste them back into the powershell

If you run into an issue where Exchange is running out of disk space on the C:\ drive, please check the logs in C:\InetPub , and C:\Program Files\Microsoft\Exchange Server\V15\Logging. If those directories are quite large you can run the following powershell script. It would also be a good idea to set it up as a scheduled task so the issue doesn’t reoccur.

 

gci ‘C:\Program Files\Microsoft\Exchange Server\V15\Logging’,’C:\inetpub\logs’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-30) | Remove-Item