小编aml*_*ssb的帖子

管道进入 ScriptBlock

我试图在 PowerShell 中找到一些灵活更改/替换管道元素的方法:

Function Where-DirectlyReportsTo {
    Param (
        [Parameter(
            ValueFromPipeline = $true,
            HelpMessage = "The ADUser object to be tested"
        )]
        [Microsoft.ActiveDirectory.Management.ADUser] $ADUser,
        [Parameter( 
            Mandatory = $true,
            ValueFromPipeline = $false,
            Position = 0
        )]
        [String] $mgrDN
    )
    Process {
        If ($ADUser) {
            If ($ADUser.Manager -eq $mgrDN) { Return $ADUser }
        }
    }
}

$Properties = @("Manager")
$users = Get-ADUser -Filter * -SearchBase $OU -Properties $Properties
[ScriptBlock] $sb = {Where-DirectlyReportsTo "CN=Colonel Foobar,$OU"}
$DNs = $users | $sb | %{$_.DistinguishedName}
Run Code Online (Sandbox Code Playgroud)

我想返回向 Foobar …

powershell pipe scriptblock

2
推荐指数
2
解决办法
6141
查看次数

标签 统计

pipe ×1

powershell ×1

scriptblock ×1