英文:
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
- 并添加 header 为
ConsistencyLevel: 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"
}
]
}
]
}
英文:
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"
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论