通过 C# 在 Azure AD 中访问 'PasswordNeverExpires' 属性
Access 'PasswordNeverExpires' property in Azure AD via C#
我有下面的 C# 代码,它非常适合查询 Azure AD,但我还需要阅读 属性 'PasswordNeverExpires',如下面的屏幕截图所示。我在此处的完整 MS 列表中看不到 属性 - https://docs.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0 - only a 'passwordPolicies' property which returns "DisablePasswordExpiration" for all our users which doesn't tally up with the results shown in AD manager. I can see plenty of powershell scripts, for example here - https://serverfault.com/questions/730189/powershell-find-all-users-with-password-never-expires - 其中提到了 'passwordNeverExpires' 属性 但这仅在我 运行 我的 C# 脚本时显示为空白.
string Url = $"{config.ApiUrl}v1.0/users?$select=userPrincipalName,lastPasswordChangeDateTime,PasswordNeverExpires,passwordNeverExpires";
do {
string JSON = await apiCaller.CallWebApiAndProcessResultASync(Url, result.AccessToken, Display);
Url = AADR.OdataNextLink;
} while (AADR.OdataNextLink != null);
您在 this post 中找到的 powershell 脚本适用于 AD 而不是 AAD。所以它不适用于 AAD。 AAD 模块中没有名为 PasswordNeverExpires
的 属性。
PowerShell 脚本:
您可以使用以下 PowerShell cmdlet 查看单个用户的密码是否设置为永不过期(参考 here):
Get-AzureADUser -ObjectId <user id or UPN> | Select-Object UserprincipalName,@{
N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
}
cmdlet 将 PasswordPolicies -contains "DisablePasswordExpiration"
别名为新 属性 PasswordNeverExpires
.
要查看所有用户的密码永不过期设置,运行 以下 cmdlet:
Get-AzureADUser -All $true | Select-Object UserprincipalName,@{
N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
}
微软图表:
由于 MS Graph user resource type 中没有 PasswordNeverExpires
属性,您应该使用 MS Graph 查询 passwordPolicies
属性。
GET https://graph.microsoft.com/v1.0/users?$select=userPrincipalName,lastPasswordChangeDateTime,passwordPolicies
然后您将在响应中得到 "passwordPolicies": "DisablePasswordExpiration"
。使用自己的代码逻辑来处理(定义一个PasswordNeverExpires
,设置为true
)。
我有下面的 C# 代码,它非常适合查询 Azure AD,但我还需要阅读 属性 'PasswordNeverExpires',如下面的屏幕截图所示。我在此处的完整 MS 列表中看不到 属性 - https://docs.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0 - only a 'passwordPolicies' property which returns "DisablePasswordExpiration" for all our users which doesn't tally up with the results shown in AD manager. I can see plenty of powershell scripts, for example here - https://serverfault.com/questions/730189/powershell-find-all-users-with-password-never-expires - 其中提到了 'passwordNeverExpires' 属性 但这仅在我 运行 我的 C# 脚本时显示为空白.
string Url = $"{config.ApiUrl}v1.0/users?$select=userPrincipalName,lastPasswordChangeDateTime,PasswordNeverExpires,passwordNeverExpires";
do {
string JSON = await apiCaller.CallWebApiAndProcessResultASync(Url, result.AccessToken, Display);
Url = AADR.OdataNextLink;
} while (AADR.OdataNextLink != null);
您在 this post 中找到的 powershell 脚本适用于 AD 而不是 AAD。所以它不适用于 AAD。 AAD 模块中没有名为 PasswordNeverExpires
的 属性。
PowerShell 脚本:
您可以使用以下 PowerShell cmdlet 查看单个用户的密码是否设置为永不过期(参考 here):
Get-AzureADUser -ObjectId <user id or UPN> | Select-Object UserprincipalName,@{
N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
}
cmdlet 将 PasswordPolicies -contains "DisablePasswordExpiration"
别名为新 属性 PasswordNeverExpires
.
要查看所有用户的密码永不过期设置,运行 以下 cmdlet:
Get-AzureADUser -All $true | Select-Object UserprincipalName,@{
N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
}
微软图表:
由于 MS Graph user resource type 中没有 PasswordNeverExpires
属性,您应该使用 MS Graph 查询 passwordPolicies
属性。
GET https://graph.microsoft.com/v1.0/users?$select=userPrincipalName,lastPasswordChangeDateTime,passwordPolicies
然后您将在响应中得到 "passwordPolicies": "DisablePasswordExpiration"
。使用自己的代码逻辑来处理(定义一个PasswordNeverExpires
,设置为true
)。