I am trying to Set-ADComputer on all machines matching the filter that is added to the $servers array. But it's not working. I guess it has something to do with passing an object to a string, but I can't get my head around it. Anyone's got a golden tip?
#Get gateway
$gateway = "MGMT01"
$gatewayObject = Get-ADComputer -Identity $gateway
#Get servers
$servers=@(Get-ADComputer -Filter {OperatingSystem -like "Windows Server*"} -Properties Name | select name | ft -HideTableHeaders)
#Create list of servers
Out-File -FilePath c:\adcomputers.txt -InputObject $servers
#Set WAC delegation
ForEach ($server in $servers)
{
$nodeObject = Get-ADComputer -Identity $server
Set-ADComputer -Identity $nodeObject -PrincipalsAllowedToDelegateToAccount $gatewayObject
}
Errors:
Get-ADComputer : Cannot bind parameter 'Identity'. Cannot convert the "Microsoft.PowerShell.Commands.Internal.Format.FormatEndData" value of type "Microsoft.PowerShell.C ommands.Internal.Format.FormatEndData" to type "Microsoft.ActiveDirectory.Management.ADComputer".
At C:\Users\SA.****\Desktop\inventorize-honolulu-incl-sso.ps1:7 char:40 + $nodeObject = Get-ADComputer -Identity $server + ~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
Set-ADComputer : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Users\SA.****\Desktop\inventorize-honolulu-incl-sso.ps1:8 char:26 + Set-ADComputer -Identity $nodeObject -PrincipalsAllowedToDelegateToAc ... + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-ADComputer], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADComputer