I have this portion of code that is throwing an invalid enumeration context error.
$ADComputers1 = (get-adcomputer -Filter {enabled -eq $true} -ResultPageSize 500 -ResultSetSize $null -Properties instanceType, IPv4Address, IPv6Address, isCriticalSystemObject, isDeleted, KerberosEncryptionType, LastBadPasswordAttempt, LastKnownParent, localPolicyFlags, Location, CannotChangePassword)
foreach ($computer in $ADComputers1){
$values += [PSCustomObject]@{
instanceType=$computer.instanceType #check
IPv4Address=$computer.IPv4Address #fail
IPv6Address=$computer.IPv6Address #fail
isCriticalSystemObject=$computer.isCriticalSystemObject
isDeleted=$computer.isDeleted
KerberosEncryptionType=$computer.KerberosEncryptionType
LastBadPasswordAttempt=$computer.LastBadPasswordAttempt
LastKnownParent=$computer.LastKnownParent #fail
localPolicyFlags=$computer.localPolicyFlags
Location=$computer.Location
CannotChangePassword=$computer.CannotChangePassword
}
}
I have looked online and found multiple errors similar to the one that is being thrown. In doing so, I have adjusted the -Filter, -ResultPageSize, and shortened the number of properties being accessed multiple times, yet this error is always thrown.
The rest of this code is checking about 70 properties fine, but this section, no matter how small or large I make it, is always throwing an error.
Any help would be appreciated.