I am using the PnP approach for getting the publishing site template and creating a new sitecollection and applying the template so that i get the replica of the source site.
I am getting the error- Scope of template does not match target while running
the below powershell script to apply the template -
$web="https://shareptdev.sharepoint.com/sites/newpub/replicasite
$templateFile = "E:\Path\template.xml";
Apply-PnPProvisioningTemplate -Web $web -Path $templateFile
The variable $web must be your site context must use the Get-PnPWeb on the connected site. Something like this:
$siteUrl = "https://shareptdev.sharepoint.com/sites/newpub/replicasite"
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$web = Get-PnPWeb
$templateFile = "E:\Path\template.xml"
Apply-PnPProvisioningTemplate -Web $web -Path $templateFile
Related
Can someone share powershell script of creating new web application in Sharepoint 2019 WITH SQL SA authentication? I have found so many scripts which just talk to windows authtication of SQL Server but I have Azure managed SQL instance linked with Sharepoint server 2019.
Please help.
By doing some research I got working script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Define Variables for Web Application Creation
$WebAppName = "abc.xyz.com"
$WebAppURL = "http://abc01"
$WebAppPort = 9000
$ContentDBName = "WSS_Contents_Abc"
$AppPoolName = "SPABC"
$AppPoolAccount = "Test\ABC"
$DatabaseServer = "sql-managedinstance-902932test.net" #Alias of your DB Server
#Authentication Provider
$AuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication
-DisableKerberos $FarmAccountLogin = "Test\ABCSQL";
$FarmAcountObj = Get-Credential -Credential $FarmAccountLogin;
#Create new Web Application
New-SPWebApplication -name $WebAppName -port $WebAppPort -URL $WebAppURL -
ApplicationPool $AppPoolName -ApplicationPoolAccount (Get-SPManagedAccount
$AppPoolAccount) -AuthenticationMethod NTLM -AuthenticationProvider
$AuthProvider -DatabaseServer $DatabaseServer -DatabaseCredentials
$FarmAcountObj -DatabaseName $ContentDBName
I want to create a Team by using an azure function triggered by an Azure Queue.
Unfortunetly when I run the code it is not working inside the Azure Function.
I'm wondering. Is there a way to create a Microsoft Team using PowerShell inside an Azure Function ?
Import-module MicrosoftTeams
$group = New-Team -MailNickname "teamTitle" -displayname "teamTitle" -Visibility "private"
Add-TeamUser -GroupId $group.GroupId -User "user#etc.com"
New-TeamChannel -GroupId $group.GroupId -DisplayName "General"
Working locally. Not working within the Azure Function.
Bellow the error i'm getting :
ERROR: Import-Module : The specified module 'MicrosoftTeams' was not loaded because no valid
module file was found in any module directory. At D:\home\site\wwwroot\CreateTeam\run.ps1:3
char:1 + Import-Module MicrosoftTeams + [...]
Thank you
Based on the error message, your Function app does not have the MicrosoftTeams module installed. You need to include a reference to this module to the requirements.psd1 file (see https://learn.microsoft.com/azure/azure-functions/functions-reference-powershell#dependency-management for more details).
Currently this module is not yet natively integrated into the azure functions under powershell
To see all the available packages go in App Service -> Advanced Tools -> DebugConsole -> Powershell and run :
Write-Output ‘Getting PowerShell Module’
$result = Get-Module -ListAvailable |
Select-Object Name, Version, ModuleBase |
Sort-Object -Property Name |
Format-Table -wrap |
Out-String
Write-output `n$result
To manually add a package, It is necessary to create a directory "Module" At the same level as the directory of the function, They will be automatically preloaded.
(https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell step "Function app-level Modules folder")
After installation of the module. use below code in your script to automate the process.
$securedpassword = ConvertTo-SecureString $Password -AsPlainText -Force
$mycredentials = New-Object System.Management.Automation.PSCredential ($Username, $securedpassword )
$res = Connect-MicrosoftTeams -Credential $mycredentials
I am trying to get a user to run a powershell script through an Azure function. This script is supposed to create a site on SharePoint with some info provided by users.
I created an Azure Function App to run some PowerShell scripts. When I tried to run my code, it returned an error http 502 at Connect-PnPOnline
If I remove Connect-PnPOnline, I get a 200 response. So I am sure that it has to do with Connect-PnPOnline in my script.
I followed the post by #Lee_MSFT Get PowerShell Script to Run SharePoint Commands on Azure
and able to import modules.
using namespace System.Net
param (
[string]$projectnumber,
[string]$projectname
)
$site = "https://xxxxx.sharepoint.com/sites/projects"
$projectsite = -join($site, "/", $projectnumber)
$projecttitle = -join($projectnumber, " ", $projectname)
Connect-PnPOnline -url $site
...
I got 500 from Connect-PnPOnline -url $site and a 502 from Connect-PnPOnline -url $site -UseWebLogin
Anyone know that why I have 5xx errors while using Connect-PnPOnline?
Thanks a lot!
Make sure you have upload the PnP PowerShell module for your Azure Function, then use the PowerShell below to connect the SharePoint.
$siteURL = "https://tenant.sharepoint.com/sites/projects"
$userId = "abc#tenant.onmicrosoft.com"
$plainText= "*****"
$pwd = ConvertTo-SecureString $plainText -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential($userId,$pwd)
Connect-PnPOnline -Url $siteURL -Credentials $creds
Or use this:
Connect-PnPOnline -AppId $env:SPO_AppId -AppSecret $env:SPO_AppSecret -Url "https://tenant.sharepoint.com/sites/projects"
SPO_AppId - Set the value to the Client ID you copied in the first step when you created your app on your tenant.
SPO_AppSecret - Set the value to the Client Secret that you copied in the first step when you created your app on your tenant.
I suggest you check the steps in the article below.
Azure Functions For SharePoint Operations Using PnP PowerShell
This article shows a tutorial how to deploy some resources from ARM templates in a powershell runbook. And as I understand, it will download the template and the parameters files in the specific path. But how can that work in an automated Runbook without having any directly attached storage to the automation account. Obviously, I'm misunderstanding something...
I mean the Get-AzureStorageFileContent command:
# Create a new context
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -
StorageAccountKey $StorageAccountKey
Get-AzureStorageFileContent -ShareName 'resource-templates' -Context
$Context -path 'TemplateTest.json' -Destination 'C:\Temp'
$TemplateFile = Join-Path -Path 'C:\Temp' -ChildPath $StorageFileName
# Deploy the storage account
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -
TemplateFile $TemplateFile -TemplateParameterObject $Parameters
Do you know how to understand this, or are there some better methods to reach the goal?
You can use -TemplateParameterUri and -TemplateUri and give publicly available urls that where the tempaltes are stored.
After consulting the Microsoft Support I am able to kick off a Docker container via Azure Automation with the following code:
$connection = Get-AutomationConnection -Name AzureRunAsConnection
$secpasswd = ConvertTo-SecureString "132asdf9asdf342" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ("somecontainerregistry", $secpasswd)
Connect-AzureRmAccount -ServicePrincipal -Tenant $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint
New-AzureRmContainerGroup -RegistryCredential $credentials -ResourceGroupName automation-rg -Name jjcontainer03 -Image somecontainerregistry.azurecr.io/etl-pipeline -OsType Linux -DnsNameLabel aci-etl-pipeline-01 -RestartPolicy Never -Command "scrapy crawl data"
This seems to work fine when I test the pane inside the Azure Automation Portal, but when I schedule it to run every hour, I only see that the Runbook job has been executed (at the correct time), without creating a new Azure instance. Should I remove the old instance every time or is there something else I am missing?
If you are specifying the script to create a container with a static name - such as the one in your case - it will not be recreated since AzureRM module detects that the said container group already exists. Try adding 'Remove-AzureRmContainerGroup ...' one line above the 'New-AzureRmContainerGroup ...'
You can use a new guid as the name of the container if you want a unique name.