Make sure the user running the script is in the security group that has been configured for the environment. Does not matter if you are Power Platform Administrator role or system administrator. You also need to be in that group.