Running PowerShell in SIF using the Command Task

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












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",
"-Wait",
"-Verbose"
]






My Parameters PS1 file.



$configsRoot = Join-Path $PSScriptRoot Configs

$sitecoreDSC = @
Path = Join-Path $configsRoot dsc.json


echo $sitecoreDSC


My install PS1 file



. $PSScriptRootparameters.ps1

Install-SitecoreConfiguration @sitecoreDSC


On the Get-Children command my error is this. It seems like it is trying to run the arg on its on command:




Get-ChildItem : Cannot find path 'C:ghScriptTestPrepServer-Path' because it does not exist.
At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicTasksInvoke-CommandTask.ps1:31 char:13
+ & $Path $Arguments | Out-Default
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:ghScriptTestPrepServer-Path:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand




On the Start-DscConfiguration my error is this. This is because Start-DscConfiguration was executed with specifying the path. Again, the args were ignored.




Invoke-CommandTask : Cannot convert 'System.Management.Automation.PSObject' to the type 'System.String' required by parameter 'Path'. Specified method is not supported.
At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicInstall-SitecoreConfiguration.ps1:253 char:21
+ & $entry.Task.Command @paramSet | Out-Default
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CommandTask








share|improve this question
























    up vote
    3
    down vote

    favorite












    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",
    "-Wait",
    "-Verbose"
    ]






    My Parameters PS1 file.



    $configsRoot = Join-Path $PSScriptRoot Configs

    $sitecoreDSC = @
    Path = Join-Path $configsRoot dsc.json


    echo $sitecoreDSC


    My install PS1 file



    . $PSScriptRootparameters.ps1

    Install-SitecoreConfiguration @sitecoreDSC


    On the Get-Children command my error is this. It seems like it is trying to run the arg on its on command:




    Get-ChildItem : Cannot find path 'C:ghScriptTestPrepServer-Path' because it does not exist.
    At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicTasksInvoke-CommandTask.ps1:31 char:13
    + & $Path $Arguments | Out-Default
    + ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (C:ghScriptTestPrepServer-Path:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand




    On the Start-DscConfiguration my error is this. This is because Start-DscConfiguration was executed with specifying the path. Again, the args were ignored.




    Invoke-CommandTask : Cannot convert 'System.Management.Automation.PSObject' to the type 'System.String' required by parameter 'Path'. Specified method is not supported.
    At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicInstall-SitecoreConfiguration.ps1:253 char:21
    + & $entry.Task.Command @paramSet | Out-Default
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CommandTask








    share|improve this question






















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      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",
      "-Wait",
      "-Verbose"
      ]






      My Parameters PS1 file.



      $configsRoot = Join-Path $PSScriptRoot Configs

      $sitecoreDSC = @
      Path = Join-Path $configsRoot dsc.json


      echo $sitecoreDSC


      My install PS1 file



      . $PSScriptRootparameters.ps1

      Install-SitecoreConfiguration @sitecoreDSC


      On the Get-Children command my error is this. It seems like it is trying to run the arg on its on command:




      Get-ChildItem : Cannot find path 'C:ghScriptTestPrepServer-Path' because it does not exist.
      At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicTasksInvoke-CommandTask.ps1:31 char:13
      + & $Path $Arguments | Out-Default
      + ~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (C:ghScriptTestPrepServer-Path:String) [Get-ChildItem], ItemNotFoundException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand




      On the Start-DscConfiguration my error is this. This is because Start-DscConfiguration was executed with specifying the path. Again, the args were ignored.




      Invoke-CommandTask : Cannot convert 'System.Management.Automation.PSObject' to the type 'System.String' required by parameter 'Path'. Specified method is not supported.
      At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicInstall-SitecoreConfiguration.ps1:253 char:21
      + & $entry.Task.Command @paramSet | Out-Default
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CommandTask








      share|improve this question












      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",
      "-Wait",
      "-Verbose"
      ]






      My Parameters PS1 file.



      $configsRoot = Join-Path $PSScriptRoot Configs

      $sitecoreDSC = @
      Path = Join-Path $configsRoot dsc.json


      echo $sitecoreDSC


      My install PS1 file



      . $PSScriptRootparameters.ps1

      Install-SitecoreConfiguration @sitecoreDSC


      On the Get-Children command my error is this. It seems like it is trying to run the arg on its on command:




      Get-ChildItem : Cannot find path 'C:ghScriptTestPrepServer-Path' because it does not exist.
      At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicTasksInvoke-CommandTask.ps1:31 char:13
      + & $Path $Arguments | Out-Default
      + ~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (C:ghScriptTestPrepServer-Path:String) [Get-ChildItem], ItemNotFoundException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand




      On the Start-DscConfiguration my error is this. This is because Start-DscConfiguration was executed with specifying the path. Again, the args were ignored.




      Invoke-CommandTask : Cannot convert 'System.Management.Automation.PSObject' to the type 'System.String' required by parameter 'Path'. Specified method is not supported.
      At C:Program FilesWindowsPowerShellModulesSitecoreInstallFramework1.2.1PublicInstall-SitecoreConfiguration.ps1:253 char:21
      + & $entry.Task.Command @paramSet | Out-Default
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CommandTask










      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 11 at 18:23









      Chris Auer

      6,0761737




      6,0761737




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          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.



          1. Create a psm1 file

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

          3. 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






          share|improve this answer






















          • The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
            – Kieranties
            Aug 11 at 19:51










          • I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
            – Chris Auer
            Aug 11 at 20:02










          • Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
            – Kieranties
            Aug 11 at 20:06










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "664"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13304%2frunning-powershell-in-sif-using-the-command-task%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          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.



          1. Create a psm1 file

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

          3. 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






          share|improve this answer






















          • The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
            – Kieranties
            Aug 11 at 19:51










          • I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
            – Chris Auer
            Aug 11 at 20:02










          • Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
            – Kieranties
            Aug 11 at 20:06














          up vote
          3
          down vote



          accepted










          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.



          1. Create a psm1 file

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

          3. 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






          share|improve this answer






















          • The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
            – Kieranties
            Aug 11 at 19:51










          • I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
            – Chris Auer
            Aug 11 at 20:02










          • Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
            – Kieranties
            Aug 11 at 20:06












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          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.



          1. Create a psm1 file

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

          3. 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






          share|improve this answer














          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.



          1. Create a psm1 file

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

          3. 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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 11 at 19:53

























          answered Aug 11 at 19:48









          Kieranties

          47126




          47126











          • The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
            – Kieranties
            Aug 11 at 19:51










          • I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
            – Chris Auer
            Aug 11 at 20:02










          • Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
            – Kieranties
            Aug 11 at 20:06
















          • The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
            – Kieranties
            Aug 11 at 19:51










          • I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
            – Chris Auer
            Aug 11 at 20:02










          • Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
            – Kieranties
            Aug 11 at 20:06















          The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
          – Kieranties
          Aug 11 at 19:51




          The configuration guide available at: dev.sitecore.net/Downloads/Sitecore_Installation_Framework/1x/… should explain things further
          – Kieranties
          Aug 11 at 19:51












          I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
          – Chris Auer
          Aug 11 at 20:02




          I started to do this in a repo of SIX and switched to tasks thinking it would be more consistent. Maybe I will just go back to that route. Thanks.
          – Chris Auer
          Aug 11 at 20:02












          Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
          – Kieranties
          Aug 11 at 20:06




          Tasks will be simpler and easier to share as raw PowerShell in configs will be more difficult to modify. Registration is really simple. Please also check the examples here (notably 6.modules.json and the extensions.psm1) github.com/Kieranties/SIfSug/tree/master/Examples
          – Kieranties
          Aug 11 at 20:06












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13304%2frunning-powershell-in-sif-using-the-command-task%23new-answer', 'question_page');

          );

          Post as a guest













































































          這個網誌中的熱門文章

          tkz-euclide: tkzDrawCircle[R] not working

          How to combine Bézier curves to a surface?

          1st Magritte Awards