Skip to content

Instantly share code, notes, and snippets.

@ElakkuvanR
Last active July 4, 2023 13:44
Show Gist options
  • Save ElakkuvanR/88b03f033489b368ed10f1765bf01cd1 to your computer and use it in GitHub Desktop.
Save ElakkuvanR/88b03f033489b368ed10f1765bf01cd1 to your computer and use it in GitHub Desktop.
# Create session and log to Sitecore
[CmdletBinding(DefaultParameterSetName = "no-arguments")]
Param (
[Parameter(Mandatory = $true, HelpMessage = "The remote CM URL")]
[string]$remoteCMUrl,
[Parameter(Mandatory = $true, HelpMessage = "User name under PSE Security Group")]
[string]$username,
[Parameter(Mandatory = $true, HelpMessage = "Password")]
[string]$password,
[Parameter(Mandatory = $true, HelpMessage = "Base XML File name to create the package")]
[string]$baseXmlFileName,
[Parameter(Mandatory = $true, HelpMessage = "Name of the package")]
[string]$packageName
)
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Import-Module -Name ./SPE
$pseArgs = @{
"packageName" = $packageName;
"baseXmlFileName" = $baseXmlFileName
}
try {
$session = New-ScriptSession -ConnectionUri $remoteCMUrl -Username $username -Verbose -Password $password
Write-Host 'Started creating the content the package'
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
$packageFile = "$SitecorePackageFolder\$(($using:pseArgs).packageName)"
$solutionFile = "$SitecorePackageFolder\$(($using:pseArgs).baseXmlFileName)"
$simpleProcessingContext = New-Object -TypeName Sitecore.Install.Framework.SimpleProcessingContext
[Sitecore.Install.PackageGenerator]::GeneratePackage($solutionFile, $packageFile, $simpleProcessingContext);
} -AsJob -Verbose
# Run the above Create Package as Job and poll it till completion
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
Write-Host 'Package has been created successfully '
}
catch {
Write-Host $_.Exception
exit
} finally {
Stop-ScriptSession -Session $session
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment