How to make RunBook recognize DateTime type?

949 Views Asked by At

I am creating a Powershell workflow in Azure Automation. When setting DateTime type Set-AutomationVariable with function, Recognized as a string. Please let me know if you know how to solve it.

workflow variabletest{

     function Test-DateTime {
        $Now = Get-Date
       Set-AutomationVariable -Name 'VariableDateTime' -Value ($Now)
    }

     Test-DateTime

}

After execution, the value of the 'VariableDateTime' confirmed from the Azure portal is as follows:

Name: VariableDateTime
Type: String
Value: 2019-12-12T06:35:23.208367+00:00

If there is Set-AutomationVariable outside the function, it has been confirmed that it becomes DateTime type.

Thank you.

1

There are 1 best solutions below

0
Joy Wang On

I can reproduce your issue, seems that it is by design of Get-Date command.

See the Outputs:

When a DateTime object is sent down the pipeline to a cmdlet such as Add-Content that expects string input, PowerShell converts the object to a String object.

Functions that need to be aware of the pipeline must be built with pipeline support.