On two different machines joined to the same Windows 2008 R2 Active Directory domain, a Windows 7 workstation and a Windows 2008 R2 server, I am getting the following error when running a 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 : A parameter cannot be found that matches parameter name 'PipelineVariable'.
At C:\Users\User1\Desktop\Find-PossibleMissingSPN.ps1:37 char:114
+ Get-ADObject -LDAPFilter $filter -SearchBase $DN -SearchScope Subtree -Proper ties $propertylist -PipelineVariable <<<< account | ForEach-Object {
+ CategoryInfo : InvalidArgument: (:) [Get-ADObject], ParameterBi ndingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory .Management.Commands.GetADObject
Various google searches have not yielded an answer. Does anyone know how to resolve this? Here's the actual code:
#.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
}
}
}
}