我正在Azure Automation中创建Powershell工作流。 使用函数设置日期时间类型Set-AutomationVariable
时, 识别为字符串。如果您知道如何解决它,请告诉我。
workflow variabletest{
function Test-DateTime {
$Now = Get-Date
Set-AutomationVariable -Name 'VariableDateTime' -Value ($Now)
}
Test-DateTime
}
执行后,从 Azure 门户确认的'VariableDateTime'
的值如下所示:
Name: VariableDateTime
Type: String
Value: 2019-12-12T06:35:23.208367+00:00
如果函数外部有Set-AutomationVariable
,则已确认它变为 DateTime 类型。
谢谢。
我可以重现您的问题,似乎是Get-Date
命令的设计。
查看输出:
当 DateTime 对象沿着管道发送到需要字符串输入的 cmdlet(如添加内容(时,PowerShell 会将该对象转换为字符串对象。
需要了解管道的函数必须使用管道支持进行构建。