June 23, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….etc

PowerShell (Part 5) – Security Groups

Now we can create start looking at the more serious stuffs, such as creating security groups and assigning users

1- Create a Security Group

In order to create a security group, we can simple do:

New-MsolGroup -DisplayName "SocialMedia" -Description "Social Media"


2- Retrieve a Security Group

We can either do a Get-MsolGroup which will list all the groups, or a better and cleaner way doing is by filtering by a specific keyword

Get-MsolGroup | Where-Object {$_.DisplayName -eq "SocialMedia"}


3- List a Security Group members

If you want to display the users in a certain Security Group, we can simply do:

$LogiSam = Get-MsolGroup | Where-Object {$_.DisplayName -eq "LogiSam"}
Get-MsolGroupMember -GroupObjectId $LogiSam.ObjectId

4- Add a member to a Security Group

In order to add a new member to an existing Security Group, we can do: