Hello Paul,
Hereâs how the command works
Get-AzureADUser command will try to fetch the Account in Azure AD with the provided UPN viz user@domain.com.
since this command has many member properties, we can use select-object (alternatively Select) to select specific properties of it.
By default, there is no property directly from the command we used, so we want to perform some operation and get the data that is required, so we use the format @{Name = âNameâ; Expression = {ââ}}
Here,
-
To query the user accountâs password type, i.e. expires or never expires, we need to check the property PasswordPolicies.
-
If this contains DisablePasswordExpiration, then PasswordNeverExpires will be âTRUEâ which means the account is set to expire
In Detail:
-
To check this, you can type:
Get-AzureADUser -ObjectId $UPN | Select-Object UserprincipalName, PasswordPolicies
Since PasswordPolicies is property of the command, and we have already piped it out, we can just select the property again by $_.propertyname
where, $_ has the current item in the pipeline
An example:
command|Select PropertyName1, @{
N="name";E={"$_.PropertyName2"}
}
is same as
Command|select PropertyName1,PropertyName2
Note that @{N =ânâ; E={e}} (common syntax) is used while select-object is being used.
-
If the property PasswordPolicies contains DisablePasswordExpiration, then PasswordNeverExpires will be âTRUEâ which means the account is set to expire
so we have the expression as below:
$_.PasswordPolicies -contains "DisablePasswordExpiration"
which we use it in command as
Select-Object UserprincipalName,@{
N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
Hope this solves your queryâŚ