簡體   English   中英

一種使用GraphAPI從Exchange服務器提取更深入的用戶對象數據的方法?

[英]A way to pull more in-depth user object data from the Exchange server using GraphAPI?

我正在研究一個Python腳本,該腳本從AD和Graph API(v1.0)中提取用戶數據,以對遇到帳戶問題(郵箱問題,資源調配等)的用戶執行“運行狀況檢查”。

我目前正在尋找與PowerShell命令等效的圖形:

Get-MsolUser -UserPrincipalName MAIL_ADDRESS@domain.com).errors[0].ErrorDetail.objecterrors.errorrecord.ErrorDescription

我花了一些時間搜索GraphAPI文檔,甚至撥通了響應對象本身的模板,但無法找到除高級面值(如UPN,電話等東西)之外返回的任何用戶對象屬性。數字等。擴展屬性是我可以找到的唯一遠程深入的屬性,甚至還不是很詳細。

有誰知道此Powershell命令的等效圖,或者即使有其他方法可以從Exchange服務器中提取一些更深層次的用戶對象數據,那也很棒!

在鏈接下面,您可以找到可以在Azure AD上執行的操作的列表

Azure AD Graph API

為了獲取用戶詳細信息,您可以從powershell調用以下api:

GET https://graph.windows.net/myorganization/users/ {user_id}?api-version

要從Powershell調用它,您可以按照以下代碼片段進行操作,只需將下面的api網址替換為用戶特定的網址即可。

 $response = Invoke-WebRequest -Uri "https://main.b2cadmin.ext.azure.com/api/trustframework?tenantId=$AzureSubscriptionTenantId&overwriteIfExists=$overwriteIfExists" -Method POST -Body $strBody -ContentType "application/xml" -Headers $htHeaders -UseBasicParsing -ErrorAction SilentlyContinue 

可以返回具有以下詳細信息的json對象:

 "odata.metadata": "https://graph.windows.net/myorganization/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element", "odata.type": "Microsoft.DirectoryServices.User", "objectType": "User", "objectId": "13addec1-c5ae-47f5-a1fe-202be14b1570", "deletionTimestamp": null, "accountEnabled": true, "signInNames": [], "assignedLicenses": [ { "disabledPlans": [], "skuId": "6fd2c87f-b296-42f0-b197-1e91e994b900" } ], "assignedPlans": [ { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "exchange", "servicePlanId": "efb87545-963c-4e0d-99df-69c6916d9eb0" }, { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "SharePoint", "servicePlanId": "5dbe027f-2339-4123-9542-606e4d348a72" }, { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "SharePoint", "servicePlanId": "e95bec33-7c88-4a70-8e19-b10bd9d0c014" }, { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "MicrosoftCommunicationsOnline", "servicePlanId": "0feaeb32-d00e-4d66-bd5a-43b5b83db82c" }, { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "MicrosoftOffice", "servicePlanId": "43de0ff5-c92c-492b-9116-175376d08c38" }, { "assignedTimestamp": "2014-10-14T02:54:04Z", "capabilityStatus": "Enabled", "service": "RMSOnline", "servicePlanId": "bea4c11e-220a-4e6d-8eb8-8ea15d019f90" } ], "city": "Tulsa", "country": "United States", "creationType": null, "department": "Sales & Marketing", "dirSyncEnabled": null, "displayName": "Garth Fort", "facsimileTelephoneNumber": null, "givenName": "Garth", "immutableId": null, "jobTitle": "Web Marketing Manager", "lastDirSyncTime": null, "mail": "garthf@a830edad9050849NDA1.onmicrosoft.com", "mailNickname": "garthf", "mobile": null, "onPremisesSecurityIdentifier": null, "otherMails": [], "passwordPolicies": "None", "passwordProfile": null, "physicalDeliveryOfficeName": "20/1101", "postalCode": "74133", "preferredLanguage": "en-US", "provisionedPlans": [ { "capabilityStatus": "Enabled", "provisioningStatus": "Success", "service": "exchange" }, { "capabilityStatus": "Enabled", "provisioningStatus": "Success", "service": "MicrosoftCommunicationsOnline" }, { "capabilityStatus": "Enabled", "provisioningStatus": "Success", "service": "SharePoint" }, { "capabilityStatus": "Enabled", "provisioningStatus": "Success", "service": "SharePoint" }, { "capabilityStatus": "Enabled", "provisioningStatus": "Success", "service": "MicrosoftOffice" } ], "provisioningErrors": [], "proxyAddresses": [ "SMTP:garthf@a830edad9050849NDA1.onmicrosoft.com" ], "sipProxyAddress": "garthf@a830edad9050849NDA1.onmicrosoft.com", "state": "OK", "streetAddress": "7633 E. 63rd Place, Suite 300", "surname": "Fort", "telephoneNumber": "+1 918 555 0101", "usageLocation": "US", "userPrincipalName": "garthf@a830edad9050849NDA1.onmicrosoft.com", "userType": "Member" } 

這是用於調用相同api的python等效代碼:

########### Python 2.7 #############
import httplib, urllib, base64

# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks

headers = {
}

params = urllib.urlencode({
    # Specify values for the following required parameters
    'api-version': '1.6',
})

try:
    conn = httplib.HTTPSConnection('graph.windows.net')
    # Specify values for path parameters (shown as {...}) and request body if needed
    conn.request("GET", "/myorganization/users/{user_id}?%s" % params, "", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks

headers = {
}

params = urllib.parse.urlencode({
    # Specify values for the following required parameters
    'api-version': '1.6',
})

try:
    conn = http.client.HTTPSConnection('graph.windows.net')
    # Specify values for path parameters (shown as {...}) and request body if needed
    conn.request("GET", "/myorganization/users/{user_id}?%s" % params, "", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

希望這對您的需求有所幫助。 讓我知道是否要從Powershell調用它,我可以為您提供命令幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM