Set-MsOUserProperties
MSOnline: Update Azure AD user properties
#Requires -Version 5.1
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ParameterSetName = 'Id')]
[guid]$UserObjectId,
[Parameter(Mandatory = $true, ParameterSetName = 'Name')]
[string]$UserName,
[Parameter(ParameterSetName = 'Name')]
[Parameter(ParameterSetName = 'Id')]
[string]$DisplayName,
[string]$FirstName,
[string]$LastName,
[string]$PostalCode,
[string]$City,
[string]$Street,
[string]$PhoneNumber,
[string]$MobilePhone,
[string]$Department,
[string]$Title,
[string]$Country,
[string]$State,
[string]$UsageLocation,
[guid]$TenantId
)
Process {
try {
if ($PSCmdlet.ParameterSetName -eq 'Id') { $user = Get-MsolUser -ObjectId $UserObjectId -TenantId $TenantId -ErrorAction Stop }
else { $user = Get-MsolUser -SearchString $UserName -TenantId $TenantId -ErrorAction Stop | Select-Object -First 1 }
[hashtable]$setArgs = @{'ErrorAction' = 'Stop'; 'ObjectId' = $user.ObjectId; 'TenantId' = $TenantId}
$stringParams = @('DisplayName','FirstName','LastName','PostalCode','City','Street','PhoneNumber','MobilePhone','Department','Title','Country','State','UsageLocation')
foreach ($p in $stringParams) {
$val = Get-Variable -Name $p -ValueOnly
if (-not [System.String]::IsNullOrWhiteSpace($val)) { $setArgs.Add($p, $val) }
}
Set-MsolUser @setArgs
$result = Get-MsolUser -ObjectId $user.ObjectId -TenantId $TenantId -ErrorAction Stop | Select-Object *
$result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') -PassThru -Force
}
catch { throw }
}Unique ID of the user
Display name, Sign-In Name or UPN of the user
Display name of the user
First name of the user
Last name of the user
Postal code
City
Street address
Phone number
Mobile phone number
Department
Job title
Country
State or province
Usage location (ISO country code)
Unique ID of the tenant