找不到与参数名称匹配的参数'PipelineVariable'

在连接到同一Windows 2008 R2 Active Directory域,Windows 7工作站和Windows 2008 R2服务器的两台不同计算机上,运行PowerShell script written by a Microsoft Field Engineer I downloaded from the Microsoft TechNet Gallery时出现以下错误:

PS C:\ Users \ User1 \ Desktop> . \ Find-PossibleMissingSPN.ps1 Get-ADObject:找不到与参数名称'PipelineVariable'匹配的参数 . 在C:\ Users \ User1 \ Desktop \ Find-PossibleMissingSPN.ps1:37 char:114 Get-ADObject -LDAPFilter $ filter -SearchBase $ DN -SearchScope Subtree -Proper tie $ propertylist -PipelineVariable <<<< account | ForEach-Object {CategoryInfo:InvalidArgument :( :) [Get-ADObject],ParameterBi ndingException FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.ActiveDirectory .Management.Commands.GetADObject

各种谷歌搜索都没有得出答案 . 有谁知道如何解决这个问题?这是实际的代码:

#.Synopsis 
# To find possibly missing SPN registrations due to manual mistakes. 
[CmdletBinding()] 
Param 
( 
# start the search at this DN. Default is to search all of the domain. 
   [string]$DN = (Get-ADDomain).DistinguishedName 
) 
# 
# define the SPN service classes to look for. Other types are mostly automated and should be OK.  
# 
$servicesclasses2check = @("host", "cifs", "nfs", "http", "mssql") 
# 
# get computers and users with a nonzero SPN within the given DN. 
# 
$filter = '(&(servicePrincipalname=*)(|(objectcategory=computer)(objectcategory=person)))' 
$propertylist = @("servicePrincipalname", "samaccountname") 
Get-ADObject -LDAPFilter $filter -SearchBase $DN -SearchScope Subtree -Properties $propertylist -PipelineVariable account | ForEach-Object { 
# 
# Create list of interesting SPNs for each account. Strong assumption for all code: SPN is syntactically correct.  
# 
$spnlist = $account.servicePrincipalName | Where-Object { 
    ($serviceclass, $hostname, $service) = $_ -split '/' 
    ($servicesclasses2check -contains $serviceclass) -and -not $service 
} 
# 
# Look for cases where there is no pair of (host, host.domain) SPNs. 
# 
foreach ($spn in $spnlist) 
{ 
    ($serviceclass, $hostname, $service) = $spn -split '/' 
    if ($service) { $service = "/$service" } 
    ($fullname, $port) = $hostname -split ':' 
    if ($port) { $port = ":$port" } 
    ($shortname, $domain) = $fullname -split '[.]' 
    # 
    # define the regexp matching the missing SPN and go look for it  
    # 
    if ($domain) { 
        $needsSPN =  "${serviceclass}/${shortname}${port}${service}`$" 
        $needsSPNtxt = "${serviceclass}/${shortname}${port}${service}" 
    } else { 
        $needsSPN = "$serviceclass/${shortname}[.][a-zA-Z0-9-]+.*${port}${service}`$" 
        $needsSPNtxt = "$serviceclass/${shortname}.<domain>${port}${service}" 
    } 
    # 
    # search the array of SPNs to see if the _other_ SPN is there. If not, we have problem case.  
    # 
    if (-not ($spnlist -match $needsSPN)) 
    { 
        [PSCustomobject] @{ 
            samaccountname = $account.samaccountname 
            presentSPN = $spn 
            missingSPN = $needsSPNtxt 
        } 
    } 
}

}

回答(1)

2 years ago

-PipelineVariable通用参数仅在PowerShell v4中可用 . 您需要升级到更高版本才能使用此功能 .