【发布时间】: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