Running PowerShell in SIF using the Command Task

2018-08-11 20:08:51

I am trying to build out some simple PowerShell tasks into SIF tasks, and I am really hitting a wall with the simplest stuff. My estimation is that a Command task is for exe and console apps and not PowerShell commands. Example below.

My JSON configuration file dsc.json

{

"Parameters": {

"InstallPath": {

"Type": "Command",

"DefaultValue": "Start-DscConfiguration",

"Description": "DSC Install Path."

}

},

"Tasks": {

"Test-Get-Children": {

"Type": "Command",

"Params": {

"Path": "Get-ChildItem",

"Arguments": [

"-Path",

"*.log"

]

}

},

"Test-DSC": {

"Type": "Command",

"Params": {

"Path": "Start-DscConfiguration",

"Arguments": [

"-Path",

".//Sitecore",

"-

  • Correct. Try running Get-Help Invoke-CommandTask to see the documentation and guidance on the built in command task.

    You can import arbitrary powershell functions by registering them in a custom module.

    Create a psm1 file

    In the psm1, use Register-SitecoreInstallExtension to register the function as a task

    Add the psm1 in the modules section of your config

    This will enable you to register existing or custom functions into the scope of your install.

    E.g. Register-SitecoreInstallExtension -Command Start-DSConfiguration -As StartDSC -Type Task

    Will enable you to use the task type StartDSC in your config.

    In SIF V2, this will be even easier as a new feature simplifies custom function registration.

    If you really need or want to put raw powershell in your config, check out SIX

    2018-08-11 20:12:44