Thank you very much for the excellent answer!
However when I set it up to read port groups from a file and add permissions to a group rather than to a user it gives an error message like this:
Exception calling "SetEntityPermissions" with "2" argument(s): "The user or group named 'DOMAIN\VM-Admins' does not exist."
This group definitely exists as this command gives it back:
PowerCLI C:\Users\Desktop> Get-VIAccount -Group "DOMAIN\vm-admins"
Id Domain Description
-- ------ -----------
VM-Admins DOMAIN
I found out trial by error that I need to set $perm.Group = $false to true and now everything is fine. I have to dive deeper into this :smileyhappy:
Thank you again for the answer!