hope you are doing well
i want to use an output of users from an OU and process them into a cmdlet. i used an Array and a loop to do the job but i faced issues.
$OUpath= 'OU=xx,OU=xx,OU=xx,DC=xx,DC=xx,DC=xx'
$str= get-aduser -Filter * -SearchBase $OUpath | select-object SamAccountName
$i=0
while($i -lt $str.Length) { Get-ADPrincipalGroupMembership $str[$i] | Select-Object name,distinguishedName | select-string "Disable Screen Saver" ; $i++ }
it shows this error
Get-ADPrincipalGroupMembership : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:6 char:60
+ ... $i -lt $str.Length) { Get-ADPrincipalGroupMembership $str[$i] | Selec ...
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADPrincipalGroupMembership], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADPrincipalGroupMembership
i tried to convert the array to a string by pipeing it to out-string to a new array before the loop and didnt work out.