Reputation: 11
I have made a code for adding a template to multiple existing SharePoint sites at once with foreach and Import-csv. I think it almost works but I keep getting the same error.
PS C:\WINDOWS\System32> $adminUrl = "https://lk6y-admin.sharepoint.com"
>> Connect-SPOService -Url $adminUrl
>> $templateName = "STS#0"
>> $existingSites = Import-Csv -Path "C:\Users\stijn.mensink\try.csv"
>> $site = $site.SiteUrl
>> foreach ($site in $existingSites) {
>> $siteUrl = $site.SiteUrl
>> $siteRelativeUrl = $site.SiteRelativeUrl
>>
>> try {
>> # Get the existing site
>> $existingSite = Get-SPOSite -Identity $siteUrl -Detailed
>>
>> # Add the site template to the existing site
>> $web = Get-SPOWeb -Identity $existingSite.Url
>> $web.ApplyWebTemplate($templateName)
>> $web.Update()
>>
>> Write-Host "Template '$templateName' added successfully to $siteUrl ($siteRelativeUrl)" -ForegroundColor Green
>> }
>> catch {
>> Write-Host "Failed to add the template to $siteUrl ($siteRelativeUrl). Error: $($_.Exception.Message)" -ForegroundColor Red
>> }
>> }
I keep getting the same error:
Failed to add the template to (). Error: Cannot bind argument to parameter 'Identity' because it is null. I have checked the csv multiple times. I don't understand why it doesn't recognize the value
I was expecting that the code would pick up the value of the $siteUrl
that is in my csv
Upvotes: 0
Views: 44