繁体   English   中英

通过Exchange Online REST Api修改用户

[英]Modify Users via Exchange Online REST Api

我正在尝试制作一个可以通过Exchange Online REST API修改Exchange Online用户的PowerShell脚本。 我需要通过API设置“职务”,“城市”,“部门”和“经理”字段。 根据交流在线文档,联系人对象具有我要设置的所有必填字段。 但是,该API似乎不允许我对用户杠杆进行更改。 这有点令人困惑。

如果我尝试访问“用户”端点,则出现错误:

Invoke-RestMethod : {"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}

但是,我在Azure Active Directory中为应用程序设置了所有权限。

这是我使用的脚本:

Add-Type -Path ".\Microsoft.IdentityModel.Clients.ActiveDirectory.dll";
 
$clientId = "<<Application Client ID>>";
$certFileFullName = "<<Path to certificate file>>";
$certFilePassword = "<<Password to certificate file>>";
$tenantId = "<<Tenant ID>>";
 
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("https://login.windows.net/$tenantId/oauth2/authorize", $false);
 
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 ($certFileFullName, $certFilePassword, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet);
$clientAssertionCertificate = new-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate($clientId, $cert);
 
$authenticationResult = $authContext.AcquireToken("https://outlook.office365.com", $clientAssertionCertificate);
    
$token = $authenticationResult.AccessToken;
 
$headers = @{ 
    "Authorization" = ("Bearer {0}" -f $token);
    "User-Agent" = "SyncTool/0.1PowerShell";
    "client-request-id" = [System.Guid]::NewGuid().ToString();
    "Date" = Get-Date -Format r;
    "Accept" = "application/json";
}
 
Invoke-RestMethod -Method Get -Uri "https://outlook.office365.com/api/v1.0/Users" -Headers $headers; 

有人通过Exchange Online REST API做到了吗? 可能吗

如何开发使用仅应用程序AAD身份验证来管理Exchange Online用户的守护程序应用程序?

德米特里

您应该在公共预览中使用Office 365统一API来枚举或修改Azure Active Directory中的用户信息。 该API位于Public Preview中,我们正在积极努力将其发布到GA。 同时,如果您需要在生产设置中配置用户,请使用Azure AD Graph API 这些是用于管理目录中用户信息的受支持端点。 端点https://outlook.office365.com/api可让您指定要访问的用户邮箱,但不允许您枚举用户,因为这是目录功能。

这是使用PowerShell模块通过简单方法解决此问题的方法。 由于您已经可以使用功能强大的功能强大的PowerShell工具,因此根据我的经验,实际上没有理由手动使用REST API进行此操作。

使用MSONline模块

除了使用此模块设置管理员外,我们可以做您需要做的所有事情

  • 首先,安装MSOnline模块。
  • 接下来,用您自己的凭据替换第3行和第4行上的信息。

     import-module MSOnline $secpasswd = ConvertTo-SecureString 'P@ssw0rdHer3!' -AsPlainText -Force $credGuest = New-Object System.Management.Automation.PSCredential ('testest@sred13gmail.onmicrosoft.com', $secpasswd) connect-msolservice -credential $credGuest Get-MsolUser | ? DisplayName -eq 'JSamson' | Set-MsolUser -Department 'Ham Research Team' -Title "Lead Pork Architect" -City "Hamburg" Get-MsolUser | ? DisplayName -eq 'JSamson' | Select *Name,Title,City,Depar* | fl DisplayName : JSamson FirstName : Joe LastName : Sampson SignInName : JoeSampson@sred13gmail.onmicrosoft.com UserPrincipalName : JoeSampson@sred13gmail.onmicrosoft.com Title : Lead Pork Architect City : Hamburg Department : Ham Research Team 

设置管理员属性

事实证明,无法从此模块访问manager属性。 不知道为什么会这样。 我正在为您解决此问题,并且在完成后会更新此答案。


没有路的时候,自己做

集成了Marius Solbakken Mellum在此博客文章http://goodworkaround.com/node/73上找到的一些很棒的技巧,我们有了连接到Azure AD的基础。 接下来,使用Azure AD Graph DLL中提供的出色API(您可以使用``。\\ nuget.exe install Microsoft.IdentityModel.Clients.ActiveDirectory''的nuget命令和《 Azure AD Rest API参考指南》来获得它,这套功能已建立。

该工具包含许多辅助函数,例如Get-MSOLGraphUser和Get-MsSOLGraphUserManager。 它们主要设计为由Set-MSOLGraphUserManager cmdlet本身使用,但是您可以随意对其进行修改并将其用于您的内心内容。

该项目的新版本将在此URL上的GitHub中存在。

范例:

Set-MSOLGraphUserManager -targetUser Test -targetManager Stephen
>Successfully found user to modify PSTest
>Successfully looked up manager Stephen Owen
>Updating the manager
>Verifying manager now set for PSTest
>Getting user manager
>PSTest's manager is now Stephen Owen                                          

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM