Forum Discussion

TomWechsler's avatar
Sep 15, 2023

Part 8 - Manage Azure and Microsoft 365 with the Microsoft Graph PowerShell SDK!

 

Dear Microsoft Azure and Microsoft 365 Friends,

 

This article continues with the topic Microsoft Graph PowerShell SDK. Part 1 to 7 can be found here:

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-1-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3300352

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-2-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3302366

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-3-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3339696

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-4-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3409310

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-5-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3442453

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-6-manage-azure-and-microsoft-365-with-the-microsoft-graph/m-p/3923379

 

https://techcommunity.microsoft.com/t5/windows-powershell/part-7-manage-azure-and-microsoft-365-with-the-microsoft-graph/td-p/3924070

 

This article is now about doing some tasks with the Microsoft Graph. We work in Microsoft Teams, create a new team, channel, and add a member as an owner.

 

Create a new Team:

 

#Core Connection for Managing Teams
$scopes = @(
"Team.Create"
"TeamSettings.ReadWrite.All"
"TeamsTab.ReadWrite.All"
"TeamsTab.Create"
"TeamMember.ReadWrite.All"
"Group.ReadWrite.All"
"GroupMember.ReadWrite.All"
)
Connect-MgGraph -Scopes $scopes

 

#Retrieve Microsoft 365 Group and Team
$group = Get-MgGroup -Filter "DisplayName eq 'Cardano'"

Get-MgTeam -TeamId $group.Id

 

#Create a New Team
New-MgTeam -AdditionalProperties @{
"email address removed for privacy reasons" = "https://graph.microsoft.com/v1.0/teamsTemplates('standard')";
"displayName" = "Ethereum";
"description" = "Ethereum Team";
}

 

#List the new Microsoft Team
$group = Get-MgGroup -Filter "DisplayName eq 'Ethereum'"

Get-MgTeam -TeamId $group.Id

 

Create a new Channel in the new Team:

 

#Create a Team Channel
$group = Get-MgGroup -Filter "DisplayName eq 'Ethereum'"

$team = Get-MgTeam -TeamId $group.Id

$channelname = "Traders"
$channeldescription = "Ethereum Traders"

$channel = New-MgTeamChannel -TeamId $team.Id -DisplayName $channelname -Description $channeldescription

 

#List the new Team Channel
Get-MgTeamChannel -TeamId $team.Id -ChannelId $channel.Id

 

Add a member to the new team as an owner:

 

#Retrieve User Details
$email = "email address removed for privacy reasons"
$user = Get-MgUser -UserId $email

 

#Retrieve Team and Add an Owner
$group = Get-MgGroup -Filter "DisplayName eq 'Ethereum'"

$team = Get-MgTeam -TeamId $group.Id

$ownerproperties = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember";
"email address removed for privacy reasons" = "https://graph.microsoft.com/beta/users/" + $user.Id }

$role = "owner"

New-MgTeamMember -TeamId $team.Id -Roles $role -AdditionalProperties $ownerproperties

 

#Retrieve Team Member and Owner for the Team
Get-MgTeamMember -TeamId $team.Id | Select-Object -Property Roles,DisplayName

 

Update some properties:

 

#Lets update some properties
$params = @{
MemberSettings = @{
AllowCreateUpdateChannels = "true" #<TrueOrFalse>
}
MessagingSettings = @{
AllowUserEditMessages = "true" #<TrueOrFalse>
AllowUserDeleteMessages = "false" #<TrueOrFalse>
}
FunSettings = @{
AllowGiphy = "true" #<TrueOrFalse>
GiphyContentRating = "moderate" #<ModerateOrStrict>
}
}

Update-MgTeam -TeamId 97d4ea74-1b57-4457-b172-182d7a5d5aa5 -BodyParameter $params


So that's it again for part 8, we'll see you again in the next part! A little preview, in the next part we'll Converting Existing PowerShell Scripts. See you soon.

 

I hope this article was useful. Thank you for taking the time to read the article.

 

Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on GitHub! https://github.com/tomwechsler

No RepliesBe the first to reply

Resources