Environment Variables in a Workflow

This topic contains 1 reply, has 2 voices, and was last updated by  Simon B 3 months, 1 week ago.

  • Author
    Posts
  • #98590

    GlacialSpike
    Participant

    I'm trying to use environment variables in a workflow:

    workflow foobar
    {
        [CmdletBinding()]
        Param
        (
            [string]$Path = "$env:HOMEDRIVE\Test\Files"
        )
    }
    

    Running this workflow returns the error:

    "In a windows PowerShell workflow, parameter defaults may only be simple value types (such as integers) and strings. In addition, the type of the default value must match the type of the parameter."

    If I change the parameter to:

    C:\Test\Files

    That is a solution. But is there a way to use environment variables (in the param block), in a workflow?

    Homedrive might not always be C: in my environment.

  • #98593

    Simon B
    Participant

    Not sure what you are trying to achieve but you could use an inline script block inside your workflow like below :-

    $HomeDrive = "$env:HOMEDRIVE"
    
    workflow foobar
    {
        [CmdletBinding()]
        Param
        (
            [string]$HomeDrivePath="c:\temp"
        )
        inlinescript {
    
      foreach ($Drive in $using:HomeDrivePath) {
    
      Test-Path -Path $Drive
    
      }
      }
    }
    foobar -HomeDrivePath $HomeDrive
    

You must be logged in to reply to this topic.