我试图使用Get-NetRoute cmdlet从所有AD计算机中提取静态路由。当工作流之外运行,但只要我尝试它失败,出现以下异常的工作流程中运行相同的代码,它工作得很好:“?”当在PowerShell中作为工作流运行时,Where-Object子句失败
System.Management.Automation.ParameterBindingException: Parameter set cannot be resolved using the specified named parameters.
我可以追溯这一回位置对象过滤。注释代码行中的“?{}”部分使其失败。没有这个过滤器,它完美的作品
代码是在这里:
cd C:\Users\Public\Documents
workflow Get-StaticRoutes {
# Change the error action to 'stop' to get try/catch working
# Get-NetRoute -Protocol NetMgmt -AddressFamily IPv4 | ? { $_.DestinationPrefix -ne "0.0.0.0/0" } | % {
Get-NetRoute -Protocol NetMgmt -AddressFamily IPv4 | % {
[PSCustomObject] @{
ComputerName = $env:COMPUTERNAME
InterfaceName = $_.InterfaceAlias
InterfaceIndex = $_.InterfaceIndex
DestinationPrefix = $_.DestinationPrefix
NextHop = $_.NextHop
Comment = ""
}
}
}
# Get all computers from AD
$computers = Get-ADComputer -Filter * | % { $_.Name }
# Retrieve IP config
Get-StaticRoutes -PSComputerName $computers | Export-Csv ".\StaticRoutes.csv" -NoTypeInformation
我可以在工作流程后过滤来解决这个问题,但我想明白我做错了,因为这是ParameterBindingException默默无闻。
谢谢,
奥利维尔。
谢谢,将块放入inlinecript修复它。它只是失败时,PSComputerName是我运行该脚本的计算机。获取“Receive-Job:连接到远程服务器GB1IVJUMPBOX02失败,并显示以下错误消息:访问被拒绝”,但这是另一个问题。 –
最后一个问题解决了,我不得不以管理员身份运行PowerShell,以免在自我身上发生错误。感谢您的帮助CB! –
@Oivivier很高兴帮助! –