I am writing a script which automatically provisions users in groups when the request is sent off. I am running a check to see if it is in a specific group out of a list or contains a phrase such as HDS. I cannot currently get the “contains” command working quite right for me. Here is what I got:
$memberof = get-QADMemberOf -Identity tpatry
if($memberof -contains "HDS" -eq $true){
Write-Host "User is already a member of one of the Job Roles"}
When I run this:
$memberof = get-QADMemberOf tpatry
Write-Host $memberof
I get these groups that I am part of. This is what $memberof returns:
USERS\Domain Users USERS\CCNet-HDS-ADMIN USERS\HDS-CP-STUDENT-ACL USERS\ME-513 USERS\HDS-IT-FTE-ACL USERS\MNE-STUDENTS-O USERS\HDS-ADMIN
When I run this, just gives me a new prompt to run another prompt to input my next command.
I’ll have to look up the documentation on -contains. Seems like I’ve seen it before, yet I always overlook, or forget, that one.
Don’t know if the main issue has anything to do with what get-QADMemberOf is returning? I don’t have that function available to me, checking online looks like it might return a collection/list of objects, instead of a string? If its not a string, you may need to iterate through each item in the collection at test for the value your looking for.
If the return value IS a string, you can try the -like operator:
We can also drop to C# as needed: