【发布时间】:2019-01-17 16:14:01
【问题描述】:
是否可以将 Connect-SPOService cmdlet 与应用程序标识符和机密一起使用?我需要在 azure 函数中获取有关网站集的信息,这些信息只能通过 get-sposite cmdlet 获得。
我正在尝试设置一个 Azure 函数,该函数使用 SharePoint Online PowerShell 模块来报告所有启用了外部共享的网站集。 由于我不想在此 Azure 函数中包含我的个人凭据,因此我在 Azure AD 中设置了一个应用程序标识符。 我可以将此应用程序 ID 与 PnP Cmdlet (connect-pnponline -appid ...) 一起使用,但 pnp 命令 get-pnpsite 不会返回所需的详细信息。
下面是 pnp 框架的代码,其中所有的 Sharing* 属性都是空的。
Connect-PnPOnline -AppId $appid -AppSecret $appsecret -Url $adminUrl
$content = @()
Get-PnPTenantSite -Filter "Url -notlike ""*/personal*""" | ? {$_.SharingCapability -ne "Disabled" } | % {
$connection = Connect-PnPOnline -ReturnConnection -Url $_.url -AppId $AppId -AppSecret $AppSecret
$site = Get-PnPSite -Connection $connection;
$content += @{
title= $site.Title;
url=$site.Url;
owner=$site.Owner;
SharingCapability=$site.SharingCapability;
SharingDomainRestrictionMode=$site.SharingDomainRestrictionMode;
SharingAllowedDomainList=$site.SharingAllowedDomainList;
SharingBlockedDomainList=$site.SharingBlockedDomainList}
}
此代码有效,但需要实际的用户凭据:
param (
# Parameter help description
[Parameter(Mandatory=$true)]
[string]$TenantName,
# Parameter help description
[Parameter(Mandatory=$true)]
[string]$DestinationPath
)
$dateStr = Get-Date -Format yyyy-MM-dd_HH-mm-ss
$filename = "ExternalSharingReport_$dateStr.csv"
$content = @()
$adminUrl = "https://$TenantName-admin.sharepoint.com"
Connect-SPOService -Url $adminUrl
$content += "Title; Url; Owner; SharingCapability; SharingDomainRestrictionMode; SharingAllowedDomainList; SharingBlockedDomainList"
Get-SpoSite | ? {$_.Url -notlike "*/personal*" -AND $_.SharingCapability -ne "Disabled" } | % {
$site = Get-SPOSite $_.url;
$content += "$($site.Title); $($site.Url); $($site.Owner); $($site.SharingCapability); $($site.SharingDomainRestrictionMode); $($site.SharingAllowedDomainList); $($site.SharingBlockedDomainList)"
}
$completPath = Join-Path -Path $DestinationPath -ChildPath $filename
$content > $completPath
我希望能够像这样使用默认 cmdlet:
Connect-SPOService $adminUrl -AppId $appId -AppSecret $appSecret
【问题讨论】:
-
嗨大卫,你解决过这个问题吗?我正在尝试在 Azure 函数(不是 PNP)中使用 SP Online cmdlet,但我根本无法连接...
-
同样的问题
标签: powershell sharepoint sharepoint-online