【问题标题】:Can we use Azure AD app for app-only access for "New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials"我们可以使用 Azure AD 应用程序对 \"New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials\" 进行仅应用程序访问吗
【发布时间】:2023-02-08 22:18:30
【问题描述】:

我们有这个旧的 powershell 代码,它使用用户名/密码通过 SharePoint 验证代码。但在我们的例子中,我们为所有账户设置了 MFA,所以我们下面的代码将不起作用。我们的租户内也禁用了仅 ACS 应用程序访问。那么我们如何更新以下代码以使用 Azure AD 应用程序专用访问权限而不是用户名和密码以及 ACS 应用程序专用访问权限?

#Set Variables
$SiteURL= "https://**.sharepoint.com/sites/Marketing"
$InternalName = "MyEditor"
 
#Setup Credentials to connect
$Cred = Get-Credential
   
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
    #Get the Web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
 
    #Get the Site Column
    $SiteColumn = $Web.Fields.GetByInternalNameOrTitle($InternalName)
    $Ctx.Load($SiteColumn)
    $Ctx.ExecuteQuery()
 
    #Get the Site Column's Name,Type, ID and Group
    $SiteColumn | Select Title, TypeDisplayName, ID, Group
}
Catch {
    write-host -f Red "Error: " $_.Exception.Message
}

请记住,我们不能使用 PnP power-shell,因为它已被租户的系统管理员禁用。谢谢

【问题讨论】:

    标签: powershell azure-active-directory sharepoint-online csom


    【解决方案1】:

    我有同样的问题,Azure 系统管理员禁用任何远程脚本;然后,我需要生成 ClientID 和 Secret,允许权限并将我的 PowerShell 脚本转换为 C# 代码:(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 2019-10-08
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      相关资源
      最近更新 更多