Home ยป Office 365 ยป Set-MsolUser – Modify User Object in Office 365

Set-MsolUser – Modify User Object in Office 365

The Set-MsolUser cmdlet in PowerShell is used to modify a user object in Microsoft Office 365.

The Set-MsolUser command is used to update the basic properties of a user object in the Azure Active Directory.

In this article, we will discuss how to use the Set-MsolUser cmdlet in PowerShell to modify the basic properties of a user in Office 365.

Set-MsolUser Syntax

Set-MsolUser
   [-ImmutableId <String>]
   [-ObjectId <Guid>]
   [-UserPrincipalName <String>]
   [-BlockCredential <Boolean>]
   [-City <String>]
   [-Country <String>]
   [-Department <String>]
   [-DisplayName <String>]
   [-Fax <String>]
   [-FirstName <String>]
   [-LastName <String>]
   [-LastPasswordChangeTimestamp <DateTime>]
   [-MobilePhone <String>]
   [-Office <String>]
   [-PasswordNeverExpires <Boolean>]
   [-PhoneNumber <String>]
   [-PostalCode <String>]
   [-PreferredDataLocation <String>]
   [-PreferredLanguage <String>]
   [-SoftDeletionTimestamp <DateTime>]
   [-State <String>]
   [-StreetAddress <String>]
   [-StrongPasswordRequired <Boolean>]
   [-Title <String>]
   [-UsageLocation <String>]
   [-AlternateEmailAddresses <String[]>]
   [-StrongAuthenticationMethods <StrongAuthenticationMethod[]>]
   [-AlternateMobilePhones <String[]>]
   [-StrongAuthenticationRequirements <StrongAuthenticationRequirement[]>]
   [-StsRefreshTokensValidFrom <DateTime>]
   [-UserType <UserType>]
   [-TenantId <Guid>]
   [<CommonParameters>]

How to Update Display Name of a User in Office 365

To update the display name of a user in Office 365, use the Set-MsolUser cmdlet with the DisplayName property.

 Set-MsolUser -UserPrincipalName "[email protected]" -DisplayName " Samer Amberson"

In the above PowerShell script, the Set-MsolUser command uses the UserPrincipalName to specify the ID of a user object and the DisplayName property to update the display name for the specified user.

The DisplayName parameter specifies the display name of the user and the UserPrincipalName parameter specifies the user ID of the user.

The output of the above PowerShell script that modifies the user display name is given below.

Set-MsolUser Display Name of a User in Office 365
Set-MsolUser Display Name of a User in Office 365

Cool Tip: How to use the Get-MsolUser cmdlet in PowerShell!

How to Update the Location of a User in Office 365

To update the location of a user in Office 365, use the Set-MsolUser cmdlet with the UsageLocation parameter. The UsageLocation parameter to set the location country or region of a user. The country or region must be a two-letter ISO code.

Set-MsolUser -UserPrincipalName "[email protected]" -UsageLocation "AU"

In the above PowerShell script, the Set-MsolUser cmdlet uses the UserPrincipalName parameter to specify the user ID, in this case, โ€œ[email protected]โ€ and updates the location to AU.

How to Set the Preferred Data Location of a User in Office 365

To set the preferred data location of a user in Office 365, use the Set-MsolUser cmdlet with the PreferredDataLocation parameter. The PreferredDataLocation property specifies the preferred data location for the user.

Set-MsolUser -UserPrincipalName "[email protected]" -PreferredDataLocation "EUR"

This command sets the preferred data location property of the user whose user principal name is โ€œ[email protected]โ€ to EUR.

Cool Tip: How to use the Get-MsolCompanyAllowedDataLocation in PowerShell!

How to Block Credential for a User in Office 365

To modify the block credential for a user in Office 365, use the Set-MsolUser cmdlet with the BlockCredential parameter. The BlockCredential parameter specifies whether the user is not able to log on using their user ID.

Set-MsolUser -UserPrincipalName "[email protected]" -BlockCredential $True

This command sets the block credential to $True for a user whose user principal name is โ€œ[email protected]โ€ which blocks them from being able to sign in.

How to Set Password Never Expires for a User in Office 365

To set the password never expired for a user in Office 365, use the Set-MsolUser cmdlet with PasswordNeverExpires parameter. The PasswordNeverExpires specifies whether the user password expires periodically.

Set-MsolUser -UserPrincipalName "[email protected]" -PasswordNeverExpires $True

This command sets the user password never expires to $True for a user whose user principal name is โ€œ[email protected]โ€œ.

How to Update Office Location for a User in Office 365

To update the office location for a user in Office 365, use the Set-MsolUser cmdlet with the Office parameter. The Office parameter specifies the location of the office of the user.

Set-MsolUser -UserPrincipalName "[email protected]" -Office "Austin"   

This command sets the office location for a user whose user principal name is โ€œ[email protected]โ€ to Austin.

Conclusion

I hope the above article on how to use the Set-MsolUser cmdlet in PowerShell to update the basic properties of a user in Office 365 is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

Get-MsolUser

New-MsolUser

Remove-MsolUser

Restore-MsolUser