GraphAPI 用于获取带有员工编号的整个用户列表。

huangapple go评论109阅读模式
英文:

GraphAPI to fetch entire user list with Employeeid

问题

I am trying to fetch All users list in Azure active directory with employee id using powershell.

当我尝试使用Powershell获取Azure活动目录中具有员工ID的所有用户列表时,

When i tried with Mg-User able to fecth expected data but when trying with graphapi not getting the required information, fetching full user list with all parameters.

当我尝试使用Mg-User时,能够获取预期的数据,但尝试使用Graph API时未获取所需信息,而是获取了包含所有参数的完整用户列表。

working

正常工作

  1. Get-MgUser -Filter "endswith(mail,'@gmail.com')"
  2. https://graph.microsoft.com/beta/users (its fetching all user information)
  1. Get-MgUser -Filter "endswith(mail,'@gmail.com')"
  2. https://graph.microsoft.com/beta/users (它获取了所有用户信息)

Not working -

未正常工作 -

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

we wanted to fetch users with their emp id only for particular domain, when using filter also its fetching same data as(https://graph.microsoft.com/beta/users)

我们想仅为特定域获取带有员工ID的用户,但即使使用过滤器,它也会获取与(https://graph.microsoft.com/beta/users)相同的数据。

Please let me know if anything missing here.

请告诉我这里是否有遗漏的内容。

Script i am using which is not working, i have tried from postman which works as expected

我正在使用的脚本没有正常工作,我已经在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"

英文:

I am trying to fetch All users list in Azure active directory with employee id using powershell

When i tried with Mg-User able to fecth expected data but when trying with graphapi not getting the required information, fetching full user list with all parameters

working

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

Not working -

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

we wanted to fetch users with their emp id only for particular domain, when using filter also its fetching same data as(https://graph.microsoft.com/beta/users)

Please let me know if anything missing here.

Script i am using which is not working, i have tried from postman which works as expected

  1. $tenantID = ""
  2. $clientID = ""
  3. $clientSecret = ""
  4. $AuthBody = @{
  5. Grant_Type = "client_credentials"
  6. Scope = "https://graph.microsoft.com/.default"
  7. client_Id = $clientID
  8. Client_Secret = $clientSecret
  9. }
  10. $ConnectGraph = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $AuthBody
  11. $Headers = @{
  12. "Authorization" = "Bearer $($ConnectGraph.access_token)"
  13. "ConsistencyLevel" = "eventual"
  14. }
  15. $url = "https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(Mail,'@gmail.com')&$orderby=userPrincipalName"
  16. $userinfo = Invoke-Restmethod-Headers $Headers -URI $url -Method GET -ContentType "application/json"

答案1

得分: 1

Here is the translation of the provided text:

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

  1. GET https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(mail,'@gmail.com')&$orderby=userPrincipalName
  • 在查询中添加 count=true
  • 并添加 headerConsistencyLevel: eventual

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

  1. {
  2. "@odata.context": "https://graph.microsoft.com/beta/$metadata#users",
  3. "@odata.count": 4,
  4. "value": [
  5. {
  6. "id": "cb70c0b9-00b4-44b4-8a2e-XXXXXXX",
  7. "deletedDateTime": null,
  8. "accountEnabled": true,
  9. "ageGroup": null,
  10. "businessPhones": [],
  11. "city": null,
  12. "createdDateTime": "2023-03-27T03:44:25Z",
  13. "creationType": null,
  14. "companyName": "Hybe",
  15. "consentProvidedForMinor": null,
  16. "country": "India",
  17. "department": null,
  18. "displayName": "XXX",
  19. "employeeId": "12345",
  20. "employeeHireDate": null,
  21. "employeeLeaveDateTime": null,
  22. "employeeType": null,
  23. "faxNumber": null,
  24. "givenName": "XXXXXX",
  25. "imAddresses": [],
  26. "infoCatalogs": [],
  27. "isLicenseReconciliationNeeded": false,
  28. "isManagementRestricted": null,
  29. "isResourceAccount": null,
  30. "jobTitle": null,
  31. "legalAgeGroupClassification": null,
  32. "mail": "XXXXXX@gmail.com",
  33. "mailNickname": "ruk",
  34. "mobilePhone": "+91 91330XXXXX",
  35. "onPremisesDistinguishedName": null,
  36. "officeLocation": "Korea",
  37. "onPremisesDomainName": null,
  38. "onPremisesImmutableId": null,
  39. "onPremisesLastSyncDateTime": null,
  40. "onPremisesSecurityIdentifier": null,
  41. "onPremisesSamAccountName": null,
  42. "onPremisesSyncEnabled": null,
  43. "onPremisesUserPrincipalName": null,
  44. "otherMails": [],
  45. "passwordPolicies": null,
  46. "postalCode": null,
  47. "preferredDataLocation": null,
  48. "preferredLanguage": null,
  49. "proxyAddresses": [
  50. "smtp:XXXX@m365x562XXXX.onmicrosoft.com",
  51. "SMTP:XXXXXX@gmail.com"
  52. ],
  53. "refreshTokensValidFromDateTime": "2023-05-27T04:50:08Z",
  54. "securityIdentifier": "S-1-12-1-3413164217-1152XXXXXXX",
  55. "showInAddressList": null,
  56. "signInSessionsValidFromDateTime": "2023-05-27T04:50:08Z",
  57. "state": null,
  58. "streetAddress": null,
  59. "surname": "",
  60. "usageLocation": null,
  61. "userPrincipalName": "XXX@m365x56XXXX.onmicrosoft.com",
  62. "externalUserConvertedOn": null,
  63. "externalUserState": null,
  64. "externalUserStateChangeDateTime": null,
  65. "userType": "Member",
  66. "employeeOrgData": null,
  67. "passwordProfile": null,
  68. "assignedLicenses": [],
  69. "assignedPlans": [],
  70. "authorizationInfo": {
  71. "certificateUserIds": []
  72. },
  73. "deviceKeys": [],
  74. "identities": [
  75. {
  76. "signInType": "userPrincipalName",
  77. "issuer": "M365x56XXXXX.onmicrosoft.com",
  78. "issuerAssignedId": "XXX@m365x562XXXX.onmicrosoft.com"
  79. }
  80. ]
  81. }
  82. ]
  83. }

GraphAPI 用于获取带有员工编号的整个用户列表。

英文:

To fetch employeeid of the users with the particular domain, try the below:

  1. GET https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(mail,'@gmail.com')&$orderby=userPrincipalName
  • Add count=true to the query
  • And add header as ConsistencyLevel: eventual

I am able to fetch all the user details successfully like below:

  1. {
  2. "@odata.context": "https://graph.microsoft.com/beta/$metadata#users",
  3. "@odata.count": 4,
  4. "value": [
  5. {
  6. "id": "cb70c0b9-00b4-44b4-8a2e-XXXXXXX",
  7. "deletedDateTime": null,
  8. "accountEnabled": true,
  9. "ageGroup": null,
  10. "businessPhones": [],
  11. "city": null,
  12. "createdDateTime": "2023-03-27T03:44:25Z",
  13. "creationType": null,
  14. "companyName": "Hybe",
  15. "consentProvidedForMinor": null,
  16. "country": "India",
  17. "department": null,
  18. "displayName": "XXX",
  19. "employeeId": "12345",
  20. "employeeHireDate": null,
  21. "employeeLeaveDateTime": null,
  22. "employeeType": null,
  23. "faxNumber": null,
  24. "givenName": "XXXXXX",
  25. "imAddresses": [],
  26. "infoCatalogs": [],
  27. "isLicenseReconciliationNeeded": false,
  28. "isManagementRestricted": null,
  29. "isResourceAccount": null,
  30. "jobTitle": null,
  31. "legalAgeGroupClassification": null,
  32. "mail": "XXXXXX@gmail.com",
  33. "mailNickname": "ruk",
  34. "mobilePhone": "+91 91330XXXXX",
  35. "onPremisesDistinguishedName": null,
  36. "officeLocation": "Korea",
  37. "onPremisesDomainName": null,
  38. "onPremisesImmutableId": null,
  39. "onPremisesLastSyncDateTime": null,
  40. "onPremisesSecurityIdentifier": null,
  41. "onPremisesSamAccountName": null,
  42. "onPremisesSyncEnabled": null,
  43. "onPremisesUserPrincipalName": null,
  44. "otherMails": [],
  45. "passwordPolicies": null,
  46. "postalCode": null,
  47. "preferredDataLocation": null,
  48. "preferredLanguage": null,
  49. "proxyAddresses": [
  50. "smtp:XXXX@m365x562XXXX.onmicrosoft.com",
  51. "SMTP:XXXXXX@gmail.com"
  52. ],
  53. "refreshTokensValidFromDateTime": "2023-05-27T04:50:08Z",
  54. "securityIdentifier": "S-1-12-1-3413164217-1152XXXXXXX",
  55. "showInAddressList": null,
  56. "signInSessionsValidFromDateTime": "2023-05-27T04:50:08Z",
  57. "state": null,
  58. "streetAddress": null,
  59. "surname": "",
  60. "usageLocation": null,
  61. "userPrincipalName": "XXX@m365x56XXXX.onmicrosoft.com",
  62. "externalUserConvertedOn": null,
  63. "externalUserState": null,
  64. "externalUserStateChangeDateTime": null,
  65. "userType": "Member",
  66. "employeeOrgData": null,
  67. "passwordProfile": null,
  68. "assignedLicenses": [],
  69. "assignedPlans": [],
  70. "authorizationInfo": {
  71. "certificateUserIds": []
  72. },
  73. "deviceKeys": [],
  74. "identities": [
  75. {
  76. "signInType": "userPrincipalName",
  77. "issuer": "M365x56XXXXX.onmicrosoft.com",
  78. "issuerAssignedId": "XXX@m365x562XXXX.onmicrosoft.com"
  79. }
  80. ]

GraphAPI 用于获取带有员工编号的整个用户列表。

huangapple
  • 本文由 发表于 2023年6月26日 17:34:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定