I have a Azure PowerShell Runbook where I use SharePoint-PnP Cmdlets, which is working totally fine. But I have a problem with a function call. To mention, the script is working fine locally, but not in the Azure Runbook.
$SPCredentials = Get-AutomationPSCredential -Name 'ServiceAccount'
Connect-PnPOnline -Url $SPUrl -Credentials $SPCredentials
$SPList = New-PnPList -Title "$($ObjektNr)-$($ObjektName)" -Template DocumentLibrary -OnQuickLaunch -EnableContentTypes
Write-Output "Bibliothek erstellt"
Add-PnPContentTypeToList -List $SPList -ContentType $SPCTName -DefaultContentType
Write-Output "Inhaltstyp hinzugefügt"
Remove-PnPContentTypeFromList -List $SPList -ContentType "Dokument"
Write-Output "Inhaltstyp entfernt"
Set-PnPList -Identity $SPList -EnableContentTypes $false -EnableVersioning $true -EnableMinorVersions $false
Write-Output "Listeneinstellungen vorgenommen"
$SPList = Get-PnPList -Identity "$($ObjektNr)-$($ObjektName)"
$SPRootFolder = "$($SPList.RootFolder.Name)/"
Write-Output "Neue Bibliothek abgerufen"
$SPTerms = Get-PnPTerm -TermSet $SPTermSet -TermGroup $SPTermGroup -IncludeChildTerms -Recursive
Write-Output "Terms abgerufen"
Function getTerms($Terms)
{
Write-Output "Funktion ausgeführt"
Foreach ($Term in $Terms)
{
If ($Term.PathOfTerm.Contains(";"))
{
Add-PnPFolder -Name $Term.Name -Folder "$($SPRootFolder)$($Term.PathOfTerm.Substring(0, $Term.PathOfTerm.LastIndexOf(";")).Replace(";","/"))"
$values = @()
$splitTerms = $Term.PathOfTerm.Split(";")
$count = $splitTerms.Count - 1
For ($i=0; $i -le $count; $i++)
{
If ($i -eq 0)
{
$values += "$($SPTermGroup)|$($SPTermSet)|$($splitTerms[$i])"
}
Else
{
$values += "$($values[-1])|$($splitTerms[$i])"
}
}
Set-PnPDefaultColumnValues -List $SPList -Field "Metadaten" -Value $values -Folder "$($Term.PathOfTerm.Replace(";","/"))"
}
else
{
Add-PnPFolder -Name $Term.Name -Folder $SPRootFolder
Set-PnPDefaultColumnValues -List $SPList -Field "Metadaten" -Value $Term.Id -Folder $Term.Name
}
If ($Term.Terms.Count -gt 0)
{
getTerms($Term.Terms)
}
}
}
getTerms($SPTerms)
The problem now is where I call the function getTerms within the function getTerms (the fourth line from the bottom). It seems after calling that function again, the whole script starts from the beginning, instead of only the function with the parameters.
Thanks for any help!
Regards, Mark