add-pnpapp:远程服务器返回一个错误:(401)未授权
我遵循了本文,以便使用clientId和clientsecret使用Connect-pnPonline:
https://www.sharepointdiary.com/2019/03/connect-pnponline-with-with-appid-anpid-and-appsecret.html
https://.sharepoint.com/sites/catalog/_layouts/15/appinv.aspx 因此,我能够成功连接。
# Connect-PnPOnline -Url $SiteURL -ClientId $ClientId -ClientSecret $ClientSecret
Write-Verbose "Add and publish your app to the App Catalog...."
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Write-Verbose "Successfully added and published to the App Catalog"
Add-PnPApp : The remote server returned an error: (401) Unauthorized.
At C:\Scripts\ReleaseManagement\Publish-PnPAppToAppCatalog.ps1:55 char:2
+ Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPApp], WebException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Apps.AddApp
完整脚本:
function Publish-PnPAppToAppCatalog {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string] $SolutionAbbreviation,
[Parameter(Mandatory=$True)]
[string] $EnvironmentAbbreviation,
[Parameter(Mandatory=$True)]
[string] $SiteName,
[Parameter(Mandatory=$True)]
[string] $Path
)
$scriptsDirectory = Split-Path $PSScriptRoot -Parent
. ($scriptsDirectory + '\Common\Connect-PnPOnlineForPublishApps.ps1')
Connect-PnPOnlineForPublishApps -SolutionAbbreviation $SolutionAbbreviation `
-EnvironmentAbbreviation $EnvironmentAbbreviation `
-ConnectionType "tenant" `
-SiteName $SiteName `
-Verbose
Write-Verbose "Add and publish your app to the App Catalog...."
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Write-Verbose "Successfully added and published to the App Catalog"
}
Publish-PnPAppToAppCatalog -SolutionAbbreviation "" `
-EnvironmentAbbreviation "" `
-SiteName "" `
-Path "" `
-Verbose
function Connect-PnPOnlineForPublishApps {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string] $SolutionAbbreviation,
[Parameter(Mandatory=$True)]
[string] $EnvironmentAbbreviation,
[Parameter(Mandatory=$True)]
[ValidateSet("tenant", "sites")]
[string] $ConnectionType,
[Parameter(Mandatory=$False)]
[string] $SiteName
)
#Requires -Version 5
$scriptsDirectory = Split-Path $PSScriptRoot -Parent
. ($scriptsDirectory + '\Common\Add-AzAccountIfNeeded.ps1')
Add-AzAccountIfNeeded
. ($scriptsDirectory + '\Common\Install-AzKeyVaultModuleIfNeeded.ps1')
Install-AzKeyVaultModuleIfNeeded
Install-Module PnP.PowerShell -RequiredVersion "1.10.0" -Scope CurrentUser -Force -AllowClobber
#Site collection URL
$SiteURL = "https://<tenant>.sharepoint.com"
#Connect to SharePoint Online with ClientId and ClientSecret
Connect-PnPOnline -Url $SiteURL -ClientId "<client-id>" -ClientSecret "<client-secret>"
Get-PnPContext
Set-PnPTenant -DisableCustomAppAuthentication $false
Write-Verbose "CONNECTED.................."
更新:
我根据建议更新了脚本:
Connect-SPOService -Url $url -Credential $credential
Set-SPOTenant -DisableCustomAppAuthentication $false
#Site collection URL
$SiteURL = "https://<tenant>.sharepoint.com"
#Connect to SharePoint Online with ClientId and ClientSecret
Connect-PnPOnline -Url $SiteURL -ClientId "<client-id>" -ClientSecret "<client-secret>"
我看到一个禁止错误:
I followed this article in order to use Connect-PnPOnline using ClientID and ClientSecret:
https://www.sharepointdiary.com/2019/03/connect-pnponline-with-appid-and-appsecret.html
https://.sharepoint.com/sites/catalog/_layouts/15/appregnew.aspx
https://.sharepoint.com/sites/catalog/_layouts/15/appinv.aspx
With that I'm able to successfully connect.
After connecting, I have the following script:
# Connect-PnPOnline -Url $SiteURL -ClientId $ClientId -ClientSecret $ClientSecret
Write-Verbose "Add and publish your app to the App Catalog...."
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Write-Verbose "Successfully added and published to the App Catalog"
And I see the error:
Add-PnPApp : The remote server returned an error: (401) Unauthorized.
At C:\Scripts\ReleaseManagement\Publish-PnPAppToAppCatalog.ps1:55 char:2
+ Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPApp], WebException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Apps.AddApp
What am I missing?
Full Script:
function Publish-PnPAppToAppCatalog {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string] $SolutionAbbreviation,
[Parameter(Mandatory=$True)]
[string] $EnvironmentAbbreviation,
[Parameter(Mandatory=$True)]
[string] $SiteName,
[Parameter(Mandatory=$True)]
[string] $Path
)
$scriptsDirectory = Split-Path $PSScriptRoot -Parent
. ($scriptsDirectory + '\Common\Connect-PnPOnlineForPublishApps.ps1')
Connect-PnPOnlineForPublishApps -SolutionAbbreviation $SolutionAbbreviation `
-EnvironmentAbbreviation $EnvironmentAbbreviation `
-ConnectionType "tenant" `
-SiteName $SiteName `
-Verbose
Write-Verbose "Add and publish your app to the App Catalog...."
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Write-Verbose "Successfully added and published to the App Catalog"
}
Publish-PnPAppToAppCatalog -SolutionAbbreviation "" `
-EnvironmentAbbreviation "" `
-SiteName "" `
-Path "" `
-Verbose
function Connect-PnPOnlineForPublishApps {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string] $SolutionAbbreviation,
[Parameter(Mandatory=$True)]
[string] $EnvironmentAbbreviation,
[Parameter(Mandatory=$True)]
[ValidateSet("tenant", "sites")]
[string] $ConnectionType,
[Parameter(Mandatory=$False)]
[string] $SiteName
)
#Requires -Version 5
$scriptsDirectory = Split-Path $PSScriptRoot -Parent
. ($scriptsDirectory + '\Common\Add-AzAccountIfNeeded.ps1')
Add-AzAccountIfNeeded
. ($scriptsDirectory + '\Common\Install-AzKeyVaultModuleIfNeeded.ps1')
Install-AzKeyVaultModuleIfNeeded
Install-Module PnP.PowerShell -RequiredVersion "1.10.0" -Scope CurrentUser -Force -AllowClobber
#Site collection URL
$SiteURL = "https://<tenant>.sharepoint.com"
#Connect to SharePoint Online with ClientId and ClientSecret
Connect-PnPOnline -Url $SiteURL -ClientId "<client-id>" -ClientSecret "<client-secret>"
Get-PnPContext
Set-PnPTenant -DisableCustomAppAuthentication $false
Write-Verbose "CONNECTED.................."
UPDATE:
I updated the script as per the suggestion:
Connect-SPOService -Url $url -Credential $credential
Set-SPOTenant -DisableCustomAppAuthentication $false
#Site collection URL
$SiteURL = "https://<tenant>.sharepoint.com"
#Connect to SharePoint Online with ClientId and ClientSecret
Connect-PnPOnline -Url $SiteURL -ClientId "<client-id>" -ClientSecret "<client-secret>"
I see a Forbidden error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论