Open furieuxjk opened 6 years ago
Hi @furieuxjk That is true. Enum can only contain Constants. There would be several solutions to your problem:
Get-ADGroup
for exampleSomething like this:
Enum Groups{
"ADGroup1" = 1
"MyADgrouprw" =2
}
#CSVFile
ID;SamACcountName;EnumName
1;""AD Group 1";ADGroup1"
2;My.ADgroup.rw;MyADgrouprw
Of course, you will have to create that list in the first place, but should not be too complicated using PowerShell ;)
Thanks for reply!
In the end I did this:
in main Class I have this string array defined:
[string[]]$BaseGroupsNewEmployee
then in Constructor I have these two AD groups defined:
$this.BaseGroupsNewEmployee = "AD Group 1", "My.ADGroup.rw"
then in Method I have this:
[void]addToBaseGroupsNewEmployee() { foreach ($group in $this.BaseGroupsNewEmployee) { Add-ADPrincipalGroupMembership -Identity $this.UserName -MemberOf $this.BaseGroupsNewEmployee } }
And then just call $whateverIsHere.addToBaseGroupsNewEmployee()
Hello!
First of all - thank you for great tutorials online! I am beginner and learning how to use Classes in PowerShell.
I have AD groups with spaces in sAMAccountName like "AD Group 1" and also I have AD groups with dots like "My.ADgroup.rw", but Enum doesn't allow to use spaces or dots. How to handle this situation?
Regards, F