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!