Powershell 更新PnPApp以将SharePoint应用程序部署到SharePoint目录
我正在考虑使用PnP PowerShell命令将SharePoint应用程序部署到SharePoint目录 我成功地将包部署到应用程序目录。我现在正在创建一个脚本,以自动化在我的站点上安装解决方案的过程: 我创建了一个脚本,如下所示:Powershell 更新PnPApp以将SharePoint应用程序部署到SharePoint目录,powershell,sharepoint,sharepoint-online,Powershell,Sharepoint,Sharepoint Online,我正在考虑使用PnP PowerShell命令将SharePoint应用程序部署到SharePoint目录 我成功地将包部署到应用程序目录。我现在正在创建一个脚本,以自动化在我的站点上安装解决方案的过程: 我创建了一个脚本,如下所示: Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish $packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publi
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
$packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
Publish-PnPApp -Identity $packageInSite.Id -Scope Site
if ($packageInSite.InstalledVersion -eq $null) {
Write-Verbose "Installing app..."
Install-PnPApp -Identity $packageInSite.Id -Scope Site
}
elseif ($packageInSite.CanUpgrade -eq $true) {
Write-Verbose "Updating installed app..."
Update-PnPApp -Identity $packageInSite.Id -Scope Site
}
else {
throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
}
Connect-PnPOnline -Url "https://<tenant>.sharepoint.com" -Credentials $credential -TenantAdminUrl "https://<tenant>-admin.sharepoint.com"
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Add-PnPSiteCollectionAppCatalog -Site "https://<tenant>.sharepoint.com/sites"
$packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
Publish-PnPApp -Identity $packageInSite.Id -Scope Site
if ($packageInSite.InstalledVersion -eq $null) {
Write-Verbose "Installing app..."
Install-PnPApp -Identity $packageInSite.Id -Scope Site
} elseif ($packageInSite.CanUpgrade -eq $true) {
Write-Verbose "Updating installed app..."
Update-PnPApp -Identity $packageInSite.Id -Scope Site
} else {
throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
}
运行上述脚本时,我看到以下错误:
Error:
{"odata.error":{"code":"-2146232832, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The app for SharePoint with ID dd996c57-c36f-425a-8ede-bd77bfd24433 does not exist in the app catalog."}}}
At C:\Source...\Publish-PnPAppToAppCatalog.ps1:73 char:9
Update-PnPApp -Identity $packageInSite.Id -Scope Site
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : WriteError: (:) [Update-PnPApp], Exception
FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Apps.UpdateApp
但是,当我运行getpnpapp-Scope-Site命令时,我确实在应用程序站点目录中找到了该应用程序
我错过了什么
更新:
我将代码更新如下:
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
$packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
Publish-PnPApp -Identity $packageInSite.Id -Scope Site
if ($packageInSite.InstalledVersion -eq $null) {
Write-Verbose "Installing app..."
Install-PnPApp -Identity $packageInSite.Id -Scope Site
}
elseif ($packageInSite.CanUpgrade -eq $true) {
Write-Verbose "Updating installed app..."
Update-PnPApp -Identity $packageInSite.Id -Scope Site
}
else {
throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
}
Connect-PnPOnline -Url "https://<tenant>.sharepoint.com" -Credentials $credential -TenantAdminUrl "https://<tenant>-admin.sharepoint.com"
Add-PnPApp -Path $Path -Scope Tenant -Overwrite -Publish
Add-PnPSiteCollectionAppCatalog -Site "https://<tenant>.sharepoint.com/sites"
$packageInSite = Add-PnPApp -Path $Path -Scope Site -Overwrite -Publish
Publish-PnPApp -Identity $packageInSite.Id -Scope Site
if ($packageInSite.InstalledVersion -eq $null) {
Write-Verbose "Installing app..."
Install-PnPApp -Identity $packageInSite.Id -Scope Site
} elseif ($packageInSite.CanUpgrade -eq $true) {
Write-Verbose "Updating installed app..."
Update-PnPApp -Identity $packageInSite.Id -Scope Site
} else {
throw 'Version ' + $packageInSite.AppCatalogVersion + ' already exists.'
}
connectpnponline-Url”https://.sharepoint.com“-凭证$credential-租户身份”https://-admin.sharepoint.com"
添加PnPApp-Path$Path-Scope-Tenant-Overwrite-Publish
添加PnPSiteCollectionAppCatalog-站点“https://.sharepoint.com/sites"
$packageInSite=添加PnPApp-Path$Path-Scope站点-Overwrite-Publish
发布PnPApp-标识$packageInSite.Id-作用域站点
如果($packageInSite.InstalledVersion-eq$null){
写详细的“安装应用程序…”
安装PnPApp-标识$packageInSite.Id-作用域站点
}elseif($packageInSite.CanUpgrade-eq$true){
写详细的“更新已安装的应用程序…”
更新PnPApp-Identity$packageInSite.Id-Scope站点
}否则{
抛出'Version'+$packageInSite.AppCatalogVersion+'已存在。'
}
这会产生一个错误:
Add-PnPSiteCollectionAppCatalog : The list item could not be added or updated because duplicate values were found in the following field(s) in the list: [Site Collection Id].
At ###.ps1:55 char:5
+ Add-PnPSiteCollectionAppCatalog -Site "https://<tenant>.sharep ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPSiteCollectionAppCatalog], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Admin.AddSiteCollectionAppCatalog
Add PnPSiteCollectionAppCatalog:无法添加或更新列表项,因为在列表中的以下字段中发现重复值:[网站集Id]。
ps1:55字符:5
+添加PnPSiteCollectionAppCatalog-站点“https://.sharep ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:WriteError:(:)[Add-PnPSiteCollectionAppCatalog],服务器异常
+FullyQualifiedErrorId:异常,SharePointPnP.PowerShell.Commands.Admin.AddSiteCollectionAppCatalog
您可以尝试启用网站集应用程序目录:
Connect-PnPOnline (TenantSite URL)
Add-PnPSiteCollectionAppCatalog -Site (SiteCollection URL)
这里有一个类似的问题供您参考:
您可以尝试启用网站集应用程序目录:
Connect-PnPOnline (TenantSite URL)
Add-PnPSiteCollectionAppCatalog -Site (SiteCollection URL)
这里有一个类似的问题供您参考:
谢谢!我应该在我的代码的第一行之前添加上述两个命令吗?另外,你能给出一个SiteCollection URL的示例吗?谢谢!我应该在我的代码的第一行之前添加上述两个命令吗?另外,你能给出一个SiteCollection URL的示例吗?