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

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

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

正常工作

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

Not working -

未正常工作 -

"https://graph.microsoft.com/beta/users?$filter=endswith(mail,'@gmail.com')&$orderby=userPrincipalName
"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

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

Not working -

"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

$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" 

答案1

得分: 1

Here is the translation of the provided text:

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

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

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

{
    "@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": "XXXXXX@gmail.com",
            "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:XXXX@m365x562XXXX.onmicrosoft.com",
                "SMTP:XXXXXX@gmail.com"
            ],
            "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": "XXX@m365x56XXXX.onmicrosoft.com",
            "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": "XXX@m365x562XXXX.onmicrosoft.com"
                }
            ]
        }
    ]
}

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

英文:

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

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:

{
"@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": "XXXXXX@gmail.com",
"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:XXXX@m365x562XXXX.onmicrosoft.com",
"SMTP:XXXXXX@gmail.com"
],
"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": "XXX@m365x56XXXX.onmicrosoft.com",
"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": "XXX@m365x562XXXX.onmicrosoft.com"
}
]

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:

确定