gpt4 book ai didi

azure - 用于获取带有员工 ID 的整个用户列表的图形 API

转载 作者:行者123 更新时间:2023-12-03 06:13:04 28 4
gpt4 key购买 nike

我正在尝试使用 powershell 获取 Azure Active Directory 中包含员工 ID 的所有用户列表

当我尝试使用 Mg-User 能够获取预期数据时,但尝试使用 graphapi 时无法获取所需信息,无法获取包含所有参数的完整用户列表

工作

Get-MgUser -Filter "endswith(mail,'@gmail.com')"
https://graph.microsoft.com/beta/users (its fetching all user information)

不工作 -

"https://graph.microsoft.com/beta/users?$filter=endswith(mail,'@gmail.com')&$orderby=userPrincipalName

我们只想获取特定域的用户及其 emp id,当使用过滤器时,它也会获取与( https://graph.microsoft.com/beta/users )相同的数据

如果这里缺少任何内容,请告诉我。

我正在使用的脚本不起作用,我已经从 postman 那里尝试过,它按预期工作

$tenantID = "" 
$clientID = ""
$clientSecret = ""

$AuthBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
client_Id = $clientID
Client_Secret = $clientSecret
}
$ConnectGraph = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $AuthBody

$Headers = @{
"Authorization" = "Bearer $($ConnectGraph.access_token)"
"ConsistencyLevel" = "eventual"
}

$url = "https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(Mail,'@gmail.com')&$orderby=userPrincipalName"

$userinfo = Invoke-Restmethod-Headers $Headers -URI $url -Method GET -ContentType "application/json"

最佳答案

要获取具有特定域的用户的employeeid,请尝试以下操作:

GET https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(mail,'@gmail.com')&$orderby=userPrincipalName
  • 将 count=true 添加到查询中
  • 并将标题添加为ConsistencyLevel:最终

我能够成功获取所有用户详细信息,如下所示:

{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users",
"@odata.count": 4,
"value": [

{
"id": "cb70c0b9-00b4-44b4-8a2e-XXXXXXX",
"deletedDateTime": null,
"accountEnabled": true,
"ageGroup": null,
"businessPhones": [],
"city": null,
"createdDateTime": "2023-03-27T03:44:25Z",
"creationType": null,
"companyName": "Hybe",
"consentProvidedForMinor": null,
"country": "India",
"department": null,
"displayName": "XXX",
"employeeId": "12345",
"employeeHireDate": null,
"employeeLeaveDateTime": null,
"employeeType": null,
"faxNumber": null,
"givenName": "XXXXXX",
"imAddresses": [],
"infoCatalogs": [],
"isLicenseReconciliationNeeded": false,
"isManagementRestricted": null,
"isResourceAccount": null,
"jobTitle": null,
"legalAgeGroupClassification": null,
"mail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90c8c8c8c8c8c8d0f7fdf1f9fcbef3fffd" rel="noreferrer noopener nofollow">[email protected]</a>",
"mailNickname": "ruk",
"mobilePhone": "+91 91330XXXXX",
"onPremisesDistinguishedName": null,
"officeLocation": "Korea",
"onPremisesDomainName": null,
"onPremisesImmutableId": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSamAccountName": null,
"onPremisesSyncEnabled": null,
"onPremisesUserPrincipalName": null,
"otherMails": [],
"passwordPolicies": null,
"postalCode": null,
"preferredDataLocation": null,
"preferredLanguage": null,
"proxyAddresses": [
"smtp:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cc4c4c4c4dcf1afaaa9e4a9aaaec4c4c4c4b2f3f2f1f5ffeef3eff3fae8b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>",
"SMTP:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="025a5a5a5a5a5a42656f636b6e2c616d6f" rel="noreferrer noopener nofollow">[email protected]</a>"
],
"refreshTokensValidFromDateTime": "2023-05-27T04:50:08Z",
"securityIdentifier": "S-1-12-1-3413164217-1152XXXXXXX",
"showInAddressList": null,
"signInSessionsValidFromDateTime": "2023-05-27T04:50:08Z",
"state": null,
"streetAddress": null,
"surname": "",
"usageLocation": null,
"userPrincipalName": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84dcdcdcc4e9b7b2b1fcb1b2dcdcdcdcaaebeae9ede7f6ebf7ebe2f0aae7ebe9" rel="noreferrer noopener nofollow">[email protected]</a>",
"externalUserConvertedOn": null,
"externalUserState": null,
"externalUserStateChangeDateTime": null,
"userType": "Member",
"employeeOrgData": null,
"passwordProfile": null,
"assignedLicenses": [],
"assignedPlans": [],
"authorizationInfo": {
"certificateUserIds": []
},
"deviceKeys": [],
"identities": [
{
"signInType": "userPrincipalName",
"issuer": "M365x56XXXXX.onmicrosoft.com",
"issuerAssignedId": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f6767677f520c090a470a090d6767676711505152565c4d504c50594b115c5052" rel="noreferrer noopener nofollow">[email protected]</a>"
}
]

enter image description here

关于azure - 用于获取带有员工 ID 的整个用户列表的图形 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76555401/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com