3

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

. $PSScriptRoot\parameters.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:\gh\ScriptTest\PrepServer-Path' because it does not exist. At C:\Program Files\WindowsPowerShell\Modules\SitecoreInstallFramework\1.2.1\Public\Tasks\Invoke-CommandTask.ps1:31 char:13 + & $Path $Arguments | Out-Default + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\gh\ScriptTest\PrepServer-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 Files\WindowsPowerShell\Modules\SitecoreInstallFramework\1.2.1\Public\Install-SitecoreConfiguration.ps1:253 char:21 + & $entry.Task.Command @paramSet | Out-Default + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CommandTask

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.