Jump to content

Add Azure users to Security Group / Get Powershell script down to one line


Recommended Posts

Posted

Hi All,

 

my preferred method of managing users is to have a spreadsheet with students info in containing their usernames and passwords for all the various platforms we use. This means that its really easy to keep things consistent accross platforms and can be mail-merged into stickers for the kids diaries or reminder letters for parents.

 

I've added another tab that uses each students info to create single line powershell commands so that I have a column for "command to add user to distribution list" and it will take their username and year group from other columns and put those values in the right place in the command. This works really well for us because it means we can copy/paste 1 command for a new child or 70 for a new year group intake. We can disable an individual user or the whole class/year/school. It means we can do that without having copies of data to make CSVs that feed into a 'for each' powershell script.

 

So with the backstory over, I'm trying to add users to a security group for a single sign on application that won't accept job title or department as an attribute to assign people to year groups. I've created the security groups and have the group object IDs that can be found with a lookup in excel. The follow is the most concise script I've found but I'd like to turn it from:

 

$group = get-msolgroup | where {$_.Displayname -eq “StudentSecurityGroup”}
$users = get-msoluser  -MaxResults 2000 -Title "*Intake*" | select userprincipalname,objectid | where {$_.title -like “*Intake*”}
$users | foreach {add-msolgroupmember -groupobjectid $group.objectid -groupmembertype “user” -GroupMemberObjectId $_.objectid}

 

into something that is one line with values taken from excel, perhaps resembling this:

Get-AzureADUser -ObjectID [email protected] | select objectid | add-msolgroupmember -groupobjectid 88733a83-427e-4bb0-b3e7-ae77ee1e9258 -groupmembertype “user” -GroupMemberObjectId objectid

 

I've put some time into getting my head round it, but I'm getting stuck on what to search for that will help me get to the answer I need.

 

Any help would be much appreciated.

 

Thanks,

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...