Hi,
The below code is working but I’m currently looking for a better way and a shorter way. What the code does is that it’s skipping to remove an AD group if it’s in the $RestrictedGroups array and just moving to the next group that the user had selected in the UDTable.
@($CompTable.selectedRows.SamAccountName.ForEach( {
[bool]$RestrictedAddGroup = $false
foreach ($grp in $RestrictedGroups) {
if ($_ -like $grp) {
[bool]$RestrictedAddGroup = $true
break
}
}
if ($RestrictedAddGroup -eq $true) {
Show-UDToast -Message "Du har inte behörighet att ändra $($_)" -MessageColor 'red' -Theme 'light' -TransitionIn 'bounceInUp' -CloseOnClick -Position center -Duration 3000
return
}
else {
Add-ADGroupMember -Identity $_ -Members $Computer
if ($ActiveEventLog -eq "True") {
Write-EventLog -LogName $EventLogName -Source "AddToGroup" -EventID 10 -EntryType Information -Message "$($User) did add $($Computer) to the group $($_)`nLocal IP:$($LocalIpAddress)`nExternal IP: $($RemoteIpAddress)" -Category 1 -RawData 10, 20
}
}
} ) )
Product: PowerShell Universal
Version: 2.7.3