Replies: 3 comments 2 replies
-
Might be related to, that you missed - connection parameter on several pnp
cmdlets
Try and set those and try again
tor. 15. dec. 2022 16.50 skrev myatix ***@***.***>:
… Hi All,
I am currently in the process of creating an Azure Function that
provisions newly created SPO sites. I can get the function to work but if I
refactor the code so that my 2 connections are initialised at the beginning
of the script things start to break???
*Working...*
using namespace System.Net
param($Request)
$env:PNPPOWERSHELL_UPDATECHECK="false"
$tenant = $env:Tenant
$clientId = $env:ClientId
$certificateBase64Encoded = $env:Certificate
$templateLibUrl = $env:TemplateLibUrl
$templateFileName = $env:TemplateFileName
#$teamSiteLogo = "logo.png"
$siteDirList = "SiteDirectory"
$downloadFilePath = $PSScriptRoot
$webUrl = $Request.Body.webUrl
write-output "Starting configuration of Modern Teams Site:"
write-output $webUrl
#Applies PnP Template to newly created site
Try {
#Set Error Preference variable to Stop
$ErrorActionPreference = "Stop"
if ($webUrl -ne $null) {
$templateSiteUrl = ($templateLibUrl -Split '/')[0..4] -Join '/'
$tplSiteConnect = Connect-PnPOnline -Url $templateSiteUrl -Tenant $tenant -ClientId $clientId -CertificateBase64Encoded $certificateBase64Encoded
$templateRelUrl = ($templateLibUrl -Split '/' | Select-Object -Skip 3) -Join '/'
$templateFileUrl = "/" + $templateRelUrl + "/" + $templateFileName
Get-PnPFile -Url $templateFileUrl -Path $downloadFilePath -FileName $templateFileName -AsFile -Force -Connection $tplSiteConnect
$webConnect = Connect-PnPOnline -Url $webUrl -Tenant $tenant -ClientId $clientId -CertificateBase64Encoded $certificateBase64Encoded
$templateFilePath = $downloadFilePath + "\" + $templateFileName
Invoke-PnPSiteTemplate -Path $templateFilePath -Parameters @{"SiteUrl"=$webUrl}
# Log Site creation in Site Directory list
write-host -f Cyan "Logging Site information in Site Directory for" $webUrl
$Web = Get-PnPWeb -Connection $webConnect
$list = Get-PnPList -identity $siteDirList -Connection $tplSiteConnect
#if ($webUrl -ne $null) {
$item = @{}
$item = @{
"Title" = $Web.Title;
"URL" = $Web.URL;
"Site Description" = $Web.Description;
}
$addItem = Add-PnPListItem -List $list -Values $item -Connection $tplSiteConnect
#}
# $siteDirListUrl = "/Lists/" + $siteDirList
# write-host $siteDirListUrl
# $SiteDirList = Get-PnPList -identity $siteDirListUrl -Connection $tplSiteConnect
# write-host $siteDirList
# Add-PnPListItem -List $SiteDirList -Values @{"Title" = $Web.Title; "URL"= $Web.URL; "Site Description"= $Web.Description } -Connection $tplSiteConnect
# Set-PnPWebHeader -SiteLogoUrl $templateFilePath + "\" + $teamSiteLogo
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Finally {
#Rest Error Preference to Default
$ErrorActionPreference = "Continue"
}
#Read more: https://www.sharepointdiary.com/2019/05/sharepoint-online-handling-errors-with-try-catch-in-powershell.html#ixzz7nY5PWSiV
#Temify the Group connected site
Try {
$Site = Get-PnPTenantSite -Identity $webUrl
New-PnPTeamsTeam -GroupId $Site.GroupId.Guid -Connection $webConnect
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
# Diables Template Gallery dialog and Next Steps dialog for newly created sites in SharePoint
# $webUrl = Get-PnPWeb -Includes NextStepsFirstRunEnabled, WebTemplatesGalleryFirstRunEnabled
# $webUrl.NextStepsFirstRunEnabled = $false
# $webUrl.WebTemplatesGalleryFirstRunEnabled = $false
# $webUrl.Update()
# Invoke-PnPQuery
$webConnect = $null
$tplSiteConnect = $null
If I restructure my code as follows everything seems to break??? I don't
really see why as all I have really done is more the connections to the top
and reorder the functions I call????
*Not working*
using namespace System.Net
param($Request)
$env:PNPPOWERSHELL_UPDATECHECK="false"
$tenant = $env:Tenant
$clientId = $env:ClientId
$certificateBase64Encoded = $env:Certificate
$templateLibUrl = $env:TemplateLibUrl
$templateFileName = $env:TemplateFileName
#$teamSiteLogo = "logo.png"
$siteDirList = "SiteDirectory"
$downloadFilePath = $PSScriptRoot
$webUrl = $Request.Body.webUrl
write-output "Starting configuration of Modern Teams Site:"
write-output $webUrl
#Applies PnP Template to newly created site
Try {
#Set Error Preference variable to Stop
$ErrorActionPreference = "Stop"
$templateSiteUrl = ($templateLibUrl -Split '/')[0..4] -Join '/'
$tplSiteConnect = Connect-PnPOnline -Url $templateSiteUrl -Tenant $tenant -ClientId $clientId -CertificateBase64Encoded $certificateBase64Encoded
$webConnect = Connect-PnPOnline -Url $webUrl -Tenant $tenant -ClientId $clientId -CertificateBase64Encoded $certificateBase64Encoded
# Diables Template Gallery dialog and Next Steps dialog for newly created sites in SharePoint
$webUrl = Get-PnPWeb -Includes NextStepsFirstRunEnabled, WebTemplatesGalleryFirstRunEnabled
$webUrl.NextStepsFirstRunEnabled = $false
$webUrl.WebTemplatesGalleryFirstRunEnabled = $false
$webUrl.Update()
Invoke-PnPQuery
#Temify the Group connected site
$Site = Get-PnPTenantSite -Identity $webUrl
New-PnPTeamsTeam -GroupId $Site.GroupId.Guid -Connection $webConnect
if ($webUrl -ne $null) {
$templateRelUrl = ($templateLibUrl -Split '/' | Select-Object -Skip 3) -Join '/'
$templateFileUrl = "/" + $templateRelUrl + "/" + $templateFileName
Get-PnPFile -Url $templateFileUrl -Path $downloadFilePath -FileName $templateFileName -AsFile -Force -Connection $tplSiteConnect
$templateFilePath = $downloadFilePath + "\" + $templateFileName
Invoke-PnPSiteTemplate -Path $templateFilePath -Parameters @{"SiteUrl"=$webUrl}
# Log Site creation in Site Directory list
write-host -f Cyan "Logging Site information in Site Directory for" $webUrl
$Web = Get-PnPWeb -Connection $webConnect
$list = Get-PnPList -identity $siteDirList -Connection $tplSiteConnect
#if ($webUrl -ne $null) {
$item = @{}
$item = @{
"Title" = $Web.Title;
"URL" = $Web.URL;
"Site Description" = $Web.Description;
}
$addItem = Add-PnPListItem -List $list -Values $item -Connection $tplSiteConnect
#}
$siteDirListUrl = "/Lists/" + $siteDirList
write-host $siteDirListUrl
$SiteDirList = Get-PnPList -identity $siteDirListUrl -Connection $tplSiteConnect
write-host $siteDirList
Add-PnPListItem -List $SiteDirList -Values @{"Title" = $Web.Title; "URL"= $Web.URL; "Site Description"= $Web.Description } -Connection $tplSiteConnect
# Set-PnPWebHeader -SiteLogoUrl $templateFilePath + "\" + $teamSiteLogo
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Finally {
#Rest Error Preference to Default
$ErrorActionPreference = "Continue"
}
$webConnect = $null
$tplSiteConnect = $null
*First Error:*
$Site = Get-PnPTenantSite -Identity $webUrl
Error: Cannot bind parameter 'Identity'. Cannot convert the
"Microsoft.SharePoint.Client.Web" value of type
"Microsoft.SharePoint.Client.Web" to type
"PnP.PowerShell.Commands.Base.PipeBinds.SPOSitePipeBind".
*Second Error:*
Get-PnPFile -Url $templateFileUrl -Path $downloadFilePath -FileName
$templateFileName -AsFile -Force -Connection $tplSiteConnect
Error: The file /sites/Testfdgdfgdf/sites/SPOSiteProvisioning/Shared
Documents/site-template.xml does not exist.
For some reason the path is now shown incorrectly after having moved the
connection strings???
I guess I am doing something stupid but I am relatively new to this and
was hoping someone can point me in the right direction?
—
Reply to this email directly, view it on GitHub
<#2655>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMTDTQBIBLBYTRR4O4HPODWNM427ANCNFSM6AAAAAAS74IPS4>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply but even with the connection applied it gives the same error! :(
Error: Cannot bind parameter 'Identity'. Cannot convert the "Microsoft.SharePoint.Client.Web" value of type "Microsoft.SharePoint.Client.Web" to type "PnP.PowerShell.Commands.Base.PipeBinds.SPOSitePipeBind". |
Beta Was this translation helpful? Give feedback.
-
You need to use the -returnConnection parameter with your calls to Connect-PnPOnline, otherwise your connection variables don't actually contain a reference to the connection and additionally, each time you call Connect-PnPOnline the current connection is overwritten. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
I am currently in the process of creating an Azure Function that provisions newly created SPO sites. I can get the function to work but if I refactor the code so that my 2 connections are initialised at the beginning of the script things start to break???
Working...
If I restructure my code as follows everything seems to break??? I don't really see why as all I have really done is more the connections to the top and reorder the functions I call????
Not working
First Error:
$Site = Get-PnPTenantSite -Identity $webUrl
Error: Cannot bind parameter 'Identity'. Cannot convert the "Microsoft.SharePoint.Client.Web" value of type "Microsoft.SharePoint.Client.Web" to type "PnP.PowerShell.Commands.Base.PipeBinds.SPOSitePipeBind".
Second Error:
Get-PnPFile -Url $templateFileUrl -Path $downloadFilePath -FileName $templateFileName -AsFile -Force -Connection $tplSiteConnect
Error: The file /sites/Testfdgdfgdf/sites/SPOSiteProvisioning/Shared Documents/site-template.xml does not exist.
For some reason the path is now shown incorrectly after having moved the connection strings???
I guess I am doing something stupid but I am relatively new to this and was hoping someone can point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions