In today fast-paced business environment, management attempt to perform an Office 365 users audit might find that the company had grown faster than they kept up with. Lots of unfamiliar names with assigned licenses and difficulties telling who belonged to which department. A request was put in for the Office 365 administrator to update user profiles with additional information such as title, department, and phone. A fairly easy task to perform, but quite a tall order if the information was not populated for all 126 users.

Here is where PowerShell comes to the rescue! The tool can be leveraged and the list can be updated in a template spreadsheet to eliminate the need to edit individual profiles within Office 365 admin portal. Such tasks may take hours to complete.

 

Prerequisites:

  1. Office 365 “cloud” users. This process will not work on users that are synchronized from on-premises Active Directory via Dirsync or AAD Connect.
  2. Sign-in assistant https://www.microsoft.com/en-us/download/details.aspx?id=28177
  3. Windows Management Framework 4 https://www.microsoft.com/en-us/download/details.aspx?id=40855

 

Connecting to Exchange Online PowerShell and MS Online Service

*Everything in bold is run in PowerShell

  1. Open PowerShell as administrator
  2. Run the Connect-MSOLService cmdlet, and enter your global administrator credentials.
  3. Run the Connect to Exchange Online PowerShell cmdlets (https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx)
       a.   $UserCredential = Get-Credential – Enter Global Admin credential
       b.   $Session = New-PSSession – ConfigurationName Microsoft.Exchange – ConnectionUri https://outlook.office365.com/powershell-liveid/-                   Credential $UserCredential – Authentication Basic – AllowRedirectionc.     
       c.   Import-PSSession $Session

 

Modifying Title and Department values

  1. Format the CSV file accordingly to update the title or department attributes in Office 365.
  2. Within PowerShell reference the CSV file as a variable. The path must be valid to the .CSV file, in this example I have the CSV stored in the C:\CSV directory.
        a.  $user_file2 = Import-CSV c:\csv\%CSVNAME%.csv      
  3. Execute the second line of the script to push the values in the CSV into the Office 365 objects.
        b.   $user_file2 | ForEach {Set-msoluser -UserPrincipalName $_.UserPrincipalName -Title $_.Title -Department $_.Department}

ExampleCSV:

 

Modifying Exchange Mailbox Custom Attribute values

  1. Format the CSV file accordingly to update the customattribute1 and customattribute2 values.
  2. Within PowerShell reference the CSV file as a variable. The path must be valid to the .CSV file, in this example I have the CSV stored in the C:\CSV directory.
       a.  $user_file1 = Import-CSV c:\csv\%CSVNAME%.csv
  3. Execute the second line of the script to push the values in the CSV into the Office 365 mailbox objects.
       b.    $user_file1 | ForEach {Set-mailbox $_.UserPrincipalName -CustomAttribute1 $_.CustomAttribute1 -CustomAttribute2                                     $_.CustomAttribute2}

Example CSV:

 

Majority of the tasks that are done within the Office 365 admin portal can be done via PowerShell scripting. With the example script noted, attributes can be updated to the requested user profile fields and save a large amount of time to update users’ profile.

If you need further assistance with Office 365, feel free to reach out to us by submitting a contact form below or register for our upcoming webinar on Upgrading Microsoft Dynamics GP.