I'm working with Sitecore 9.2 , And I need to create a custom button inside custom ribbon when click on button open dialog so the content author can select date and then i will do my business function after that
- first i created the ribbon
- then i created the button
- i created the command class which will contain the powershell code and my business function
the problem that the powershell script didn't executed , i need to know how to write powershell inside C# class and why my code didn't executed
public override void Execute(CommandContext context){
using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default", true)){
var command = "$result = Read-Variable -Parameters ` @{ Name=\"from\"; Value=[System.DateTime]::Now.AddDays(-5); Title=\"Start Date\"; Tooltip=\"Date since when you want the report to run\"; Editor=\"date time\"}` -Description \"This Dialog shows less editors, it doesn't need tabs as there is less of the edited variables\" `" +
" -Title \"Initialise various variable types (without tabs)\" -Width 500 -Height 480 -OkButtonName \"Proceed\" -CancelButtonName \"Abort\" ";
List<object> results;
results = scriptSession.ExecuteScriptPart(command, false);
}
}
i found this error in the SPE log
Exception: System.InvalidOperationException Message: Non interactive session cannot perform an interactive operation requested by the 'Read-Variable' command.