To run commands or expressions in a workflow that are valid in Windows PowerShell, but not valid in workflows, run the commands in an inlineScript activity. You can use also an inlineScript activity to run Windows PowerShell scripts (.ps1 files) in a workflow.
Try this ( not tested )
workflow Get-StaticRoutes
{
inlinescript { Get-NetRoute -Protocol NetMgmt -AddressFamily IPv4 |
? { $_.DestinationPrefix -ne "0.0.0.0/0" } |
% {
[PSCustomObject] @{
ComputerName = $env:COMPUTERNAME
InterfaceName = $_.InterfaceAlias
InterfaceIndex = $_.InterfaceIndex
DestinationPrefix = $_.DestinationPrefix
NextHop = $_.NextHop
Comment = ""
}
}
}
}
side note:
$env:computername
outside the inlinescipt activity resolve to local computer name. Inside the inlinescipt activity resolve to the remote computer name.- the object returned by a workflow is a serialized object and not the object created in the inlinescript activity or workflow process ( this means, in simple terms, that you can't have object method but only the properties of the object )