У меня есть сценарий powershell, который отлично работает в ISE, однако в RunDeck при запуске его из файла я получаю следующую ошибку
В строке отсутствует терминатор: '. 09:19:34 + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordException 09:19:34 + FullyQualifiedErrorId: TerminatorExpectedAtEndOfString 09: 19: 34
09:19:34 «mCd» не распознается как внутреннее иливнешняя команда, 09:19:34 работающая программа или командный файл. 09:19:34 Результат: 1
Я не понимаю, что не так? Это только ограничение RunDeck? Скрипт powershell содержит XML. Я даже пытался поместить содержимое XML в отдельный XML-файл и, однако, использовать get-content. Вот код (я знаю об орфографических ошибках, это "хорошо")
Param(
[Parameter(Mandatory=$true,Position=0)]
[string]$pass,
[Parameter(Mandatory=$true)]
[string]$teamSiteTitel
)
#Credentials for Service Account
Set-Location "\\Server\c$\admin_apps\scripts\SP_IS"
#Credentials for Service Account
$credentialXml = Get-Content -Path .\cred.xml
$credential = @"
$credentialXml
"@
$tenantName =Select-Xml -Content $credential -XPath "//tenant" | foreach {$_.node.InnerXML}
$username =Select-Xml -Content $credential -XPath "//username" | foreach {$_.node.InnerXML}
$password= ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password
$rootSite =Select-Xml -Content $credential -XPath "//rootSite" | foreach {$_.node.InnerXML}
# Connect to to Office 365
try{
Connect-PnPOnline -Url ("https://{0}-admin.sharepoint.com/" -f $tenantName) -Credential $cred
write-host "Info: Connected succesfully to Office 365" -foregroundcolor green
}
catch{
write-host "Error: Could not connect to Office 365" -foregroundcolor red
Break new-SPOnlineSite
}
#Connect to the Site Collection
try{
write-host "Connect to site collection"
Connect-PnPOnline –Url ("https://{0}.sharepoint.com/" -f $tenantName) –Credentials $cred
}catch{
write-host "Error: Could not connect to site 365" -foregroundcolor red
$tenantName
}
#Load SharePoint CSOM Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
#TeamSite parameter
#$teamSiteTitel = Read-Host -Prompt "Please enter the Teamsite Titel"
$template = "STS#0"
$pagesLibrary = "Pages"
$PageName="HomePage"
$PageTemplate = "CompanyName2ColumnsPageLayout"
#Create the new team site
$ParentSiteUrl = $rootSite+ "/InternalServices/"
#$ParentSiteUrl = Read-Host -Prompt "Please enter the Teamsite Parent Url"
#Connect to the Site Collection
write-host "Connect to Parent site"
Connect-PnPOnline –Url $ParentSiteUrl –Credentials $cred
Write-Output "Creating new Team Site"
$NewWeb = New-PnPWeb -Title $teamSiteTitel -Url $teamSiteTitel -Template $template -BreakInheritance
$SiteUrl= $NewWeb.Url
##Enable The Push Notifications feature
#Write-Output "Activating Notifications feature"
#Enable-PnPFeature -Identity 41e1d4bf-b1a2-47f7-ab80-d5d6cbba3092 -Scope Web
#Connect to the new team site
Write-Output "Connecting to new Team Site"
Connect-PnPOnline -Url $SiteUrl -Credentials $cred
#create Groups
Write-Output "creating groups"
$ownerGroupName = $teamSiteTitel + "_Owners"
$CompanyNameAllName = "CompanyName_Allnew"
New-PnPGroup -Title $ownerGroupName -ErrorAction SilentlyCont
New-PnPGroup -Title $CompanyNameAllName -ErrorAction SilentlyCont
#Set group permission, owner = full control, member = control
Write-Output "Setting group permissions"
Set-PnPGroupPermissions -Identity $ownerGroupName -AddRole 'Edit' -Web (Get-PnPWeb)
Set-PnPGroupPermissions -Identity $CompanyNameAllName -AddRole 'Contribute' -Web (Get-PnPWeb)
#Add team site owner to owner group
Write-Output "Adding Owner to group"
Add-PnPUserToGroup -LoginName $username -Identity $ownerGroupName
#Activate the "publishing" feature
Write-Output "Activating publishing feature"
Enable-PnPFeature -Identity 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb -Scope Web
##Remove Getting Started and Site feed Webpart
Write-Output "Removing Getting Started Webpart"
Remove-PnPWebPart -Title "Get started with your site" -ServerRelativePageUrl "/SitePages/Home.aspx"
Remove-PnPWebPart -Title "Site Feed" -ServerRelativePageUrl "/SitePages/Home.aspx"
#Deactivate "Sit Feed" feature
Write-Output "Deactivate Site Feed feature"
Disable-PnPFeature -Identity 15a572c6-e545-4d32-897a-bab6f5846e18 -Scope Web
#Add Content type
Write-Output "Adding ContenType"
Add-PnPContentTypeToList -List $pagesLibrary -ContentType "CompanyNamePage" -DefaultContentType
Add-PnPContentTypeToList -List "Financials" -ContentType "CompanyNameDocument" -DefaultContentType
#Add Publishing page
Write-Output "Adding Publishing page"
Add-PnPPublishingPage -PageName $PageName -Title $PageName -PageTemplateName $PageTemplate -Publish
#Set the new Page as home page
Set-PnPHomePage -RootFolderRelativeUrl ("{0}/{1}.aspx" -f $pagesLibrary,$PageName)
$UrlHomePage = $NewWeb.ServerRelativeUrl + "/" + $pagesLibrary + "/" +$PageName +".aspx"
#CheckOut The Page
Set-PnPFileCheckedOut -Url $UrlHomePage
#Adding Documents Webpart
Write-Output "Adding Documents Webpart"
$scriptP= "
<webParts>
<webPart xmlns='http://schemas.microsoft.com/WebPart/v3'>
<metaData>
<type name='Microsoft.SharePoint.WebPartPages.ScriptEditorWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name='ExportMode' type='exportmode'>All</property>
<property name='HelpUrl' type='string' />
<property name='Hidden' type='bool'>False</property>
<property name='Description' type='string'>Allows authors to insert HTML snippets or scripts.</property>
<property name='Content' type='string'>
<script type='text/javascript'(>);
Function SP.SOD.executeFunc {('sp.js'), ('SP.ClientContext')}
Function SP.SOD.executeFunc {('sp.search.js', 'Microsoft.SharePoint.Client.Search.Query')}
alightContentSearch('latesDocuments', 'path:\''+_spPageContextInfo.webAbsoluteUrl+''\''NOT FileType:html NOT Filetype:aspx', 'Title', 'LatestDocuments', '5', ([String]{property: 'LastModifiedTime', DESC: 1}));
</script(>);
<div id='latesDocuments'(>);</div(>);</property>
<property name='CatalogIconImageUrl' type='string' />
<property name='Title' type='string'>Latest Documents</property>
<property name='AllowHide' type='bool'>True</property>
<property name='AllowMinimize' type='bool'>True</property>
<property name='AllowZoneChange' type='bool'>True</property>
<property name='TitleUrl' type='string' />
<property name='ChromeType' type='chrometype'>TitleOnly</property>
<property name='AllowConnect' type='bool'>True</property>
<property name='Width' type='unit' />
<property name='Height' type='unit' />
<property name='HelpMode' type='helpmode'>Navigate</property>
<property name='AllowEdit' type='bool'>True</property>
<property name='TitleIconImageUrl' type='string' />
<property name='Direction' type='direction'>NotSet</property>
<property name='AllowClose' type='bool'>True</property>
<property name='ChromeState' type='chromestate'>Normal</property>
</properties>
</data>
</webPart>
</webParts>"
Add-PnPWebPartToWebPartPage -ServerRelativePageUrl $UrlHomePage -XML $scriptP -ZoneId "LeftCol" -ZoneIndex 1
#CheckIn The Page
Set-PnPFileCheckedIn -Url $UrlHomePage
#Site URL
Write-Output "Team Site Url is :" $SiteUrl