0 votes

Hello,

I want to check if a user is alredy a member of a specific group before doing sometings.

This is the piece of code that works well if I execute it on Powershell from the server :

$csvFilePath = "C:\Scripts\GRP_TST01.csv"
$csvFile = Import-Csv $csvFilePath
$members = Get-AdmGroupMember -Identity GRP_TST01 -Adaxesservice localhost
foreach ($user in $csvFile) {
if ($members.name -contains $user.login) {
           Write-Output "$user already members"
       }
}

The same code with the same csv file is not Working in my Custom Command :

foreach ($user in $csvfile) {  
   if ($members.name -contains $user.login) {
           $Context.LogMessage("$user already member of %cn%.", "Information")
       }  
}

The IF statement is never true so the block {} is not executed...

The code contains a quite similar block that is working. Users are added in the group.

foreach ($user in $csvFile) {
  try
  {
       Add-AdmGroupMember -Identity "%distinguishedName%" -Members $user.Login -Adaxesservice localhost -ErrorAction Continue -Confirm:$False
   }
   catch
  {
       $Context.LogMessage($_.Exception.Message, "Warning")
   }
}

So what's wrong??

Thanks in advance!

by (1.1k points)
0

When I execute the script from the PowerShell Script Editor it looks PS is not able to read the properties of an object.

Exemple :

Import-module Adaxes
$members = Get-AdmGroupMember -Identity GROUPNAME -Adaxesservice localhost
$members.Name >> c:\temp\members.txt

Results : I do NOT get a list of users with Property 'Name'

Directly on the servers in Powershell.exe

>>Import-module Adaxes
>>$members = Get-AdmGroupMember -Identity GROUPNAME -Adaxesservice localhost
>>$members.Name >> c:\temp\members.txt

Result: The file does contain a list of users.

A bug in Adaxes??

1 Answer

0 votes
by (1.1k points)
selected by
Best answer

Finally I did like this :

       $IsMemberofIf = get-admuser -Identity $user.login -Properties memberof -Adaxesservice localhost -ErrorAction Continue
       If ($IsMemberofIf.memberof -like '*CN=%cn%*')

Related questions

0 votes
1 answer

Hello, I have a web service that checks if a user is a member of a group. I am not concerned if they are a direct member or an indirect member of a group, but if the user is in the ... I pass it User A and Group 1. I am using ADSI, c# (.Net 4.0), and WCF.

asked Feb 23, 2014 by mbcalvin (140 points)
0 votes
1 answer

Greetings. When I create the parameters to make a business rule that looks for users whose Email Proxy Adresses does not contain 'SMTP:%userPrincipalName%', it still generates profiles ... and primary SMTP address don't match. Version is 2023 How rule is set

asked Dec 19, 2022 by MShep (80 points)
0 votes
0 answers

Hello, Is it possible to pass a comma-separated list of users (firstname.lastname or emails) in a parameter instead of a CSV? How does it translate to an array of usernames ... in the Adaxes interface. Or can the script only email the list of disabled users?

asked Oct 25, 2022 by manomano (80 points)
0 votes
1 answer

We want to check, if the number of a new team (group) is unique. The number is stored in the attribute "gidNumber". I have a business rule executing before creating ... $NULL) { $Context.Cancel("Ein Team mit dieser Team-Nummer existiert bereits!") return } }

asked Oct 13, 2020 by lohnag (160 points)
0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 points)
3,588 questions
3,277 answers
8,303 comments
548,091 users