I am triggering an SPE script from the code. SPE script contains a few checks but finally has Export-UnicornConfiguration $configurationName
.
The script runs without any errors when it is triggered through Execute Script inside CMS. The only issue is when it is triggered from the code. Am I missing anything while calling from the code?
Even from the code, all the other cmdlets like Get-Item and Get-UnicornConfiguration works fine. But below exception occurs with Export-UnicornConfiguration.
using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default", true))
{
string script = scriptItem["Script"];
scriptSession.SetVariable("ConfigurationName", _configurationName);
if (!string.IsNullOrEmpty(script))
scriptSession.ExecuteScriptPart(script, true);
}
Unicorn configuration
<configuration name="xxxxxxx_Content">
<dataProviderConfiguration enableTransparentSync="false" />
<predicate>
<include name="xxxx" database="master" path="/sitecore/content/xxxxxxx">
</include>
</predicate>
<syncConfiguration updateLinkDatabase="false" updateSearchIndex="false" />
</configuration>
ERROR: Current context is not a job (Sitecore.Jobs.AsyncUI.InvalidContextException)at Sitecore.Jobs.AsyncUI.JobContext.get_Job()
at Sitecore.Jobs.AsyncUI.SendMessageMe
ssage..ctor(Message message, Boolean postBack)
at Spe.Core.Host.ScriptingHostUserInterface.WriteProgress(Int64 sourceId, ProgressRecord record)
at System.Management.Automation.Intern
al.Host.InternalHostUserInterface.WriteProgress(Int64 sourceId, ProgressRecord record)
at Unicorn.PowerShell.PowershellProgressStatus.Report(Int32 percent)
at Unicorn.SerializationHe
lper.ReserializeConfigurations(IConfiguration[] configurations, IProgressStatus progress, ILogger additionalLogger)
Export-UnicornConfiguration : Reserialize failed. Review preceding logs for details.
At line:1 char:1
- Export-UnicornConfiguration "xxxxxxx_Content"
- CategoryInfo : NotSpecified: (:) [Export-UnicornConfiguration], InvalidOperationException
- FullyQualifiedErrorId : System.InvalidOperationException,Unicorn.PowerShell.ExportUnicornConfigurationCommand