├── .gitignore ├── 0-Connect.ps1 ├── 1-GroupsEssentials.ps1 ├── 2-TeamsEssentials.ps1 ├── 3-Hide.ps1 ├── 4-GroupsExpiration.ps1 ├── 5-SoftDelete.ps1 ├── 6-Owners.ps1 ├── 7-SensitivityLabels.ps1 ├── LICENSE ├── README.md ├── a1-HelloWorld.ps1 ├── a2-Variables.ps1 ├── a3-Storage.ps1 └── a4-Get-Teams.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /0-Connect.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 0-Connect.ps1 - connect to Microsoft 365 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | #------------------------------------------ 7 | # First install the modules... 8 | # Install-Module -Name MicrosoftTeams -Force -AllowClobber -scope CurrentUser 9 | # Install-Module -Name AzureADPreview -Force -AllowClobber -scope CurrentUser 10 | # Update-Module -Name AzureADPreview -Force 11 | # Uninstall-Module -Name AzureADPreview -Force 12 | # Get a list of modules on the computer that were installed by PowerShellGet. 13 | # Get-InstalledModule 14 | #------------------------------------------ 15 | Import-Module MicrosoftTeams 16 | Import-Module AzureADPreview 17 | 18 | # Get the credebtials... 19 | $cred = Get-Credential 20 | $cred.password.MakeReadOnly() 21 | 22 | # Connect to the Teams module 23 | Connect-MicrosoftTeams -Credential $cred 24 | 25 | # If required, connect to the AAD module 26 | # $cred should still have a password* 27 | Connect-AzureAD -Credential $cred 28 | 29 | # Connect to Exchange Online 30 | $session = New-PSSession -ConfigurationName Microsoft.Exchange ` 31 | -ConnectionUri https://ps.outlook.com/powershell/ ` 32 | -Credential $cred -Authentication Basic -AllowRedirection 33 | Import-PSSession $session -AllowClobber 34 | Write-Output "ready for Exchange Online!" 35 | 36 | # Connect to Security & Compliance 37 | $sessioncompliance = New-PSSession -ConfigurationName Microsoft.Exchange ` 38 | -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ ` 39 | -Credential $cred -Authentication Basic -AllowRedirection 40 | Import-PSSession $sessioncompliance -DisableNameChecking -Prefix "CC" 41 | Write-Output "ready for Security & Compliance!" 42 | 43 | # Remove-PSSession $session 44 | # Remove-PSSession $sessioncompliance 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | <# 53 | Remarks for using the same credetials for multiple modules: 54 | https://github.com/Azure/azure-docs-powershell-azuread/issues/169 55 | RobdeJong 56 | The password property of the credentials object is cleared after the call for security reasons - we didn't want passwords to linger around in memory for some uninvited guests to use. 57 | If you want to re-use the password after the connect-azuread call you should make it read-only before the cmdlet call: 58 | 59 | $cred = Get-Credential 60 | $cred.Password.Length 61 | $cred.password.MakeReadOnly() 62 | Connect-AzureAD -Credential $cred 63 | # $cred should still have a password 64 | $cred.Password.Length 65 | #> 66 | -------------------------------------------------------------------------------- /1-GroupsEssentials.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 1-GroupsEssentials.ps1 - list Office 365 groups 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | # Get all groups or a specific group 7 | Get-UnifiedGroup | ? {$_.DisplayName -eq 'Ignite'} 8 | 9 | # List all groups in descending order 10 | Get-UnifiedGroup | Select Id, DisplayName, ManagedBy, Alias, AccessType, ` 11 | WhenCreated, @{Expression={([array](Get-UnifiedGroupLinks -Identity $_.Id -LinkType ` 12 | Members)).Count }; Label='Members'} ` 13 | | Sort-Object whencreated ` 14 | | Format-Table displayname, alias, managedby, Members, accesstype, whencreated 15 | 16 | # List all private groups 17 | Get-UnifiedGroup | Where-Object {$_.AccessType -eq 'Private'} | ` 18 | Sort-Object whencreated | Format-Table displayname, alias, ` 19 | managedby, accesstype, whencreated 20 | 21 | -------------------------------------------------------------------------------- /2-TeamsEssentials.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 2-TeamsEssentials.ps1 - list and modify Teams 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | # See all available cmdlets at 5 | # https://docs.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps 6 | #--------------------------------------------------------------------------------------- 7 | 8 | # Get a list of all teams 9 | Get-Team | ? {$_.DisplayName -like 'My*'} 10 | 11 | # Create a new-Team: might take 1-2 minutes 12 | # New-Team -DisplayName "My Wednesday Project" -Description 'My Wednesday Project' -Visibility Private 13 | New-Team -DisplayName "My Thursday Project" -Description 'My Thursday Project' -Visibility Private 14 | New-Team -DisplayName "My Friday Project" -Description 'My Friday Project' -Visibility Private 15 | 16 | # Select one group we want to work with... 17 | $group = '583616b9-3191-439a-91fb-27add35dc0eb' 18 | 19 | # See all channels of that group: 'Ignite' 20 | Get-TeamChannel -GroupId $group 21 | 22 | # Create a new team channel in that group 23 | New-TeamChannel -GroupId $group -DisplayName 'My Ignite channel' -Description 'My Ignite' 24 | 25 | # See some team member settings as AllowCreateUpdateChannels, AllowDeleteChannels, etc. 26 | Get-Team -GroupId $group | fl 27 | 28 | # Get all Team members 29 | Get-TeamUser -GroupId $group 30 | 31 | # Add a new user as member to that group 32 | Add-TeamUser -GroupId $group -User nestorw@M365x251516.onmicrosoft.com 33 | Add-TeamUser -GroupId $group -User diegoS@M365x251516.onmicrosoft.com 34 | 35 | # Remove a user from the group 36 | Remove-TeamUser -GroupId $group -User diegoS@M365x251516.onmicrosoft.com 37 | 38 | # Modify that group. 39 | # See the classifications at https://protection.office.com/sensitivitylabels 40 | Set-Team -GroupId $group -DisplayName 'My Wednesday Ignite team' ` 41 | -Visibility Private ` 42 | -Classification 'Highly Confidential' ` 43 | -Description 'My Wednesday Ignite team description' ` 44 | -MailNickname 'myigniteteamwednesday1' 45 | 46 | # Note: Get-TeamGuestSettings and Set-TeamFunSettings are deprecated with 1.0 PowerShell release, and are no longer supported. 47 | # Use Get-Team and Set-Team instead. 48 | # See two group guest settings: AllowCreateUpdateChannels, AllowDeleteChannels 49 | Get-Team -GroupId $group | fl 50 | 51 | # Set new Fun settings: 52 | Set-Team -GroupId $group -AllowGiphy $true -GiphyContentRating Strict 53 | 54 | #------------------------ 55 | # Channels 56 | #------------------------ 57 | 58 | # Delete a channel: 59 | Remove-TeamChannel -GroupId $group -DisplayName 'My Ignite channel' 60 | 61 | # Note: -> The General channel cannot be removed: Message: General channel cannot be deleted. 62 | Remove-TeamChannel -GroupId $group -DisplayName 'General' 63 | 64 | # Check the existing channels 65 | Get-TeamChannel -GroupId $group 66 | 67 | #------------------------------------------ 68 | # Alternatively, use Graph API 69 | #------------------------------------------ 70 | <# 71 | Check the group properties with Graph Explorer 72 | aka.ms/ge 73 | https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayname,'my') 74 | See the channels, etc. 75 | https://graph.microsoft.com/v1.0/teams/bdebef61-fc39-45fc-9e16-ca927ecb7601/channels/ 76 | Graph API has more actions, e.g. see the channels, e.g. see the tabs... 77 | https://graph.microsoft.com/v1.0/teams/bdebef61-fc39-45fc-9e16-ca927ecb7601/channels/19:fac22556a2764f46b161940b3fc01600@thread.skype/tabs 78 | #> 79 | 80 | -------------------------------------------------------------------------------- /3-Hide.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 3-Hide.ps1 - hide a group from the global addressbook 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | # https://docs.microsoft.com/en-us/powershell/module/exchange/users-and-groups/set-unifiedgroup?view=exchange-ps 5 | #--------------------------------------------------------------------------------------- 6 | Get-UnifiedGroup 7 | 8 | # Hide a specific group from Outlook with EXO PS 9 | $groupid = '583616b9-3191-439a-91fb-27add35dc0eb' 10 | 11 | # HiddenFromAddressListsEnabled: Does the group appear in the global address list (GAL) and other address lists in your organization. 12 | Set-UnifiedGroup -Identity $groupid -HiddenFromAddressListsEnabled $false 13 | 14 | # HiddenFromExchangeClientsEnabled: Is the group hidden from Outlook clients connected to Office 365. 15 | # The group isn't visible in the Outlook left-hand navigation and isn't be visible in the global address list (GAL). 16 | # The group name won't resolve during the creation a new message in Outlook. 17 | Set-UnifiedGroup -Identity $groupid -HiddenFromExchangeClientsEnabled:$false 18 | 19 | # Hide multiple groups 20 | $groups = Get-UnifiedGroup -ResultSize Unlimited | ? {$_.DisplayName -like "My*"} 21 | $groups 22 | Foreach ($Group in $Groups) { 23 | Set-UnifiedGroup -Identity $Group.Guid -HiddenFromAddressListsEnabled $false 24 | Set-UnifiedGroup -Identity $Group.Guid -HiddenFromExchangeClientsEnabled:$false 25 | } 26 | 27 | -------------------------------------------------------------------------------- /4-GroupsExpiration.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 4-GroupsExpiration.ps1 - list and modify the groups expiration date 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | # Get the current setting 7 | Get-AzureADMSGroupLifecyclePolicy | Format-List 8 | 9 | # Update of a policy 10 | $LifetimeID = "f45c0130-82d0-4851-8e01-6d058ff73b7e" 11 | Set-AzureADMSGroupLifecyclePolicy -Id $LifetimeID ` 12 | -GroupLifetimeInDays 40 ` 13 | -ManagedGroupTypes 'All' ` 14 | -AlternateNotificationEmails admin@M365x251516.onmicrosoft.com 15 | 16 | #------------------------------------------------------------ 17 | # Removes current policy 18 | $LifetimeID = "f45c0130-82d0-4851-8e01-6d058ff73b7e" 19 | Remove-AzureADMSGroupLifecyclePolicy -Id $LifetimeID 20 | 21 | # Setup of new Groups Lifecycle policy (None, All, Selected) 22 | New-AzureADMSGroupLifecyclePolicy -GroupLifetimeInDays 60 ` 23 | -ManagedGroupTypes "All" ` 24 | -AlternateNotificationEmails admin@M365x251516.onmicrosoft.com 25 | 26 | # Get the current setting 27 | Get-AzureADMSGroupLifecyclePolicy | Format-List 28 | 29 | # Retrieves Lifecyclepolicy of a selected group 30 | Get-UnifiedGroup | Select id, displayname 31 | 32 | $group = "95bd1a4e-485b-4979-aff3-c3176d1b4eaa" 33 | Get-AzureADMSLifecyclePolicyGroup -Id $group 34 | 35 | # Renews a group by updating the RenewedDateTime property on a group to the current DateTime. 36 | Reset-AzureADMSLifeCycleGroup -GroupId $group 37 | 38 | # Adds a group to a lifecycle policy - only if ManagedGroupTypes is 'Selected'. 39 | Add-AzureADMSLifecyclePolicyGroup -Id $LifetimeID -GroupId $group 40 | #------------------------------------------------------------ 41 | 42 | -------------------------------------------------------------------------------- /5-SoftDelete.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 5-SoftDelete.ps1 - delete groups 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | # Get all groups or a specific group 7 | Get-AzureADGroup | ? {$_.DisplayName -like 'My*'} 8 | 9 | # Soft Delete a specific group 10 | $ToDelete = "ff4006fa-199b-4e01-92f5-4d93c413dcf2" 11 | Remove-AzureADGroup -ObjectId $ToDelete 12 | 13 | # Show all Soft Deleted Groups in descending order 14 | Get-AzureADMSDeletedGroup | Sort-Object DeletedDateTime -Descending | ` 15 | Format-Table Id, DisplayName, Description, Visibility, DeletedDateTime 16 | 17 | # Restore a specific soft deleted group 18 | Restore-AzureADMSDeletedDirectoryObject -Id $ToDelete 19 | 20 | # Get all groups or a specific group 21 | Get-AzureADGroup | ? {$_.DisplayName -eq 'My Ignite team'} 22 | 23 | # Hard Delete a Group 24 | Remove-AzureADMSDeletedDirectoryObject -Id $ToDelete 25 | 26 | -------------------------------------------------------------------------------- /6-Owners.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 6-Owners.ps1 - list and modify owners of a group 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | # Get Ownerless groups (< 2 owners) 7 | $OwnerlessGroups = [array](Get-UnifiedGroup | Where-Object {([array](Get-UnifiedGroupLinks ` 8 | -Identity $_.Id -LinkType Owners)).Count -lt 2}) | ` 9 | Select-Object Id, DisplayName, ManagedBy, WhenCreated, SMTPAddress 10 | $OwnerlessGroups | ft 11 | 12 | # Assign owner to the ownerless group 13 | for ($i=0; $i -lt $OwnerlessGroups.Count; $i++) 14 | { 15 | Add-UnifiedGroupLinks $OwnerlessGroups.Alias -LinkType member -Links NestorW@M365x251516.OnMicrosoft.com 16 | Add-UnifiedGroupLinks $OwnerlessGroups.Alias -LinkType Owner -Links NestorW@M365x251516.OnMicrosoft.com 17 | } 18 | 19 | # Modify owner of an existing group. The new owner must already be a member! 20 | Get-UnifiedGroup | ? {$_.DisplayName -like 'My*'} 21 | 22 | 23 | $group = "My Monday Project" 24 | Add-UnifiedGroupLinks $group -LinkType Member -Links MiriamG@M365x251516.OnMicrosoft.com 25 | Add-UnifiedGroupLinks $group -LinkType Owner -Links MiriamG@M365x251516.OnMicrosoft.com 26 | 27 | # Get all groups or a specific group 28 | Get-AzureADGroup | ? {$_.DisplayName -eq $group} 29 | 30 | $groupid = 'ff4006fa-199b-4e01-92f5-4d93c413dcf2' 31 | Get-TeamUser -GroupId $groupid 32 | 33 | # Remove user: This might take some minutes... 34 | Remove-TeamUser -GroupId $groupid -User MiriamG@M365x251516.OnMicrosoft.com 35 | 36 | # Check the result 37 | Get-TeamUser -GroupId $groupid 38 | 39 | -------------------------------------------------------------------------------- /7-SensitivityLabels.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # 7-SensitivityLabels.ps1 - Office 365 Security & Compliance Center PowerShell 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | # https://docs.microsoft.com/en-us/powershell/exchange/office-365-scc/connect-to-scc-powershell/connect-to-scc-powershell?view=exchange-ps 5 | #--------------------------------------------------------------------------------------- 6 | 7 | # Show the labels (with prefix) 8 | Get-CCLabel | ft 9 | 10 | Get-CCLabel | fl 11 | 12 | # Set a new label policy 13 | # Set-LabelPolicy -Identity -AdvancedSettings @{Key=ConvertTo-Json("value1", "value2")} 14 | 15 | # Set new labels 16 | # $guid = New-Guid 17 | # Set-Label -Identity $guid -AdvancedSettings @{Key=ConvertTo-Json("General", "Internal","Highly Confidential")} 18 | 19 | # Remove-PSSession $sessioncompliance 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Martina Grom 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Office 365 Groups and Microsoft Teams PowerShell MasterClass 2 | 3 | Demos by [atwork-it.com](https://www.atwork-it.com/). 4 | Contributors: [Martina Grom](https://twitter.com/magrom), [Toni Pohl](https://twitter.com/atwork) 5 | 6 | Management of Office 365 and Microsoft Teams can be done in a lot of ways. The following scripts show essential PowerShell scripts you need to manage your Office 365 Groups and Microsoft Teams at scale. You must be a **Global Administrator in the Microsoft 365 tenant** to run all scripts. These are the updated scripts of November 2019. Use and adapt the scripts as required. 7 | 8 | ## Required PowerShell modules 9 | 10 | You get the latest PowerShell modules from the PowerShell Gallery or remotely: 11 | 12 | - [AzureADPreview](https://www.powershellgallery.com/packages/AzureADPreview/) 13 | - [MicrosoftTeams](https://www.powershellgallery.com/packages/MicrosoftTeams/) 14 | - Remote Exchange PowerShell (Microsoft.Exchange) - see the connect script 15 | - [Office 365 Security & Compliance Center PowerShell](https://docs.microsoft.com/en-us/powershell/exchange/office-365-scc/connect-to-scc-powershell/connect-to-scc-powershell?view=exchange-ps) 16 | - Exchange PowerShell v2 modules (coming) 17 | - Graph PowerShell (coming) 18 | 19 | ## Install the modules 20 | 21 | Use the following commands to install the PowerShell modules in an environment (as Administrator) or for your current user with the command as here: 22 | 23 | ~~~~powershell 24 | Install-Module -Name MicrosoftTeams -Force -AllowClobber -scope CurrentUser 25 | Install-Module -Name AzureADPreview -Force -AllowClobber -scope CurrentUser 26 | # Update-Module -Name AzureADPreview -Force -AllowClobber 27 | ~~~~ 28 | 29 | ## Run the scripts anywhere 30 | 31 | You can use the scripts on your computer with the required modules installed, or in Azure Automation Accounts or Azure Functions as well - in all environments, where Microsoft PowerShell is supported. To start with Azure Automation Accounts, check out [Create an Azure Automation account](https://docs.microsoft.com/en-us/azure/automation/automation-quickstart-create-account). 32 | 33 | ## Structure of the scripts 34 | 35 | The scripts show demos how to manage Office 365 Groups and Microsoft Teams in an Office 365 tenant. The scripts can be used as start for adapting your custom Office 365 tenant management. To make it easy to follow, the scripts are numbered by topic. 36 | 37 | ## Cross-Reference 38 | 39 | - To see the open-source Groups Governance Toolkit by [atwork-it.com](https://www.atwork-it.com/), see https://github.com/martinagrom/Ignite2018GroupsGovernanceToolkit) 40 | - If you are interested in a **ready-to-use Governance Overview solution** visualized with Power-BI, check out [governancetoolkit365.com](https://governancetoolkit365.com/). You can register for a free trial. 41 | 42 | ## For developers 43 | 44 | Alternatively, developers can use the Microsoft Graph for accomplishing similar tasks. Check the group properties with Graph Explorer [aka.ms/ge](https://aka.ms/ge), similar like here: 45 | 46 | - https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayname,'my') 47 | - See the channels, etc. https://graph.microsoft.com/v1.0/teams/bdebef61-fc39-45fc-9e16-ca927ecb7601/channels/ 48 | - Graph API has more actions, e.g. see the channels, e.g. see the tabs... https://graph.microsoft.com/v1.0/teams/bdebef61-fc39-45fc-9e16-ca927ecb7601/channels/19:fac22556a2764f46b161940b3fc01600@thread.skype/tabs 49 | 50 | Have a good Office 365 Groups and Teams management with these PowerShell scripts! 51 | -------------------------------------------------------------------------------- /a1-HelloWorld.ps1: -------------------------------------------------------------------------------- 1 | Write-Output "Hello world at $(Get-Date)." 2 | 3 | -------------------------------------------------------------------------------- /a2-Variables.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # a2-Variables.ps1 - work with Variables 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | # https://docs.microsoft.com/en-us/azure/automation/shared-resources/variables 5 | #--------------------------------------------------------------------------------------- 6 | Write-Output "Hello, $name at $(Get-Date)" 7 | 8 | # not encrypted 9 | $SomeText1 = Get-AutomationVariable -Name "SomeText1" 10 | Write-Output "The value of 'SomeText1' is '$($SomeText1)'." 11 | 12 | # encrypted 13 | $SomeText2 = Get-AutomationVariable -Name "SomeText2" 14 | Write-Output "The value of 'SomeText2' is '$($SomeText2)'." 15 | 16 | -------------------------------------------------------------------------------- /a3-Storage.ps1: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------- 2 | # a3-Storage.ps1 - write content to an Azure Storage Blob 3 | # Microsoft Teams and Office 365 Groups PowerShell Masterclass - by @magrom and @atwork 4 | #--------------------------------------------------------------------------------------- 5 | 6 | # Create a new local logfile with some content 7 | $todaydate = Get-Date -Format yyyy-MM-dd-HH-mm-ss 8 | $logfile = "MyLogfile-$todaydate.log" 9 | $content = "$logfile`nThis is some content of the logfile." 10 | $content | Out-File -FilePath .\$logfile -NoClobber 11 | 12 | # Get a storage context 13 | $storage = Get-AutomationVariable -Name "Storage" 14 | $storagekey = Get-AutomationVariable -Name "StorageKey" 15 | 16 | $storageContext = New-AzureStorageContext -StorageAccountName $storage -StorageAccountKey $storagekey 17 | 18 | # Copy the file to the storage account with no output 19 | Set-AzureStorageBlobContent -File $logfile -Container "myfiles" -BlobType "Block" -Context $storageContext -Verbose 20 | 21 | Write-Output "Created $($logfile)." 22 | 23 | -------------------------------------------------------------------------------- /a4-Get-Teams.ps1: -------------------------------------------------------------------------------- 1 | # https://practical365.com/microsoft-365/how-to-run-powershell-scripts-to-automate-manual-processes-in-office-365/ 2 | 3 | 4 | # https://docs.microsoft.com/en-us/azure/automation/automation-first-runbook-textual#step-5---add-authentication-to-manage-azure-resources 5 | Import-Module MicrosoftTeams 6 | 7 | # Then, connect... 8 | 9 | $cred = Get-AutomationPSCredential -Name 'admin@M365x251516.onmicrosoft.com' 10 | Connect-AzAccount -Credential $cred 11 | 12 | Write-Output "Credential : $($cred.UserName)" 13 | Write-Output "Pwd : $($cred.Password)" 14 | 15 | # Connect to the Teams module 16 | Connect-MicrosoftTeams -Credential $cred 17 | 18 | # Get a list of teams 19 | $teams = Get-Team 20 | 21 | # Create a new team 22 | # $team = New-Team -DisplayName $name -Description $description -AccessType "Private" -AddCreatorAsMember $true 23 | # Add some channels 24 | #New-TeamChannel -GroupId $team.GroupId -DisplayName "Project A" 25 | #New-TeamChannel -GroupId $team.GroupId -DisplayName "Project B" 26 | 27 | Write-Output $teams 28 | 29 | Write-Output "Done." 30 | 31 | 32 | --------------------------------------------------------------------------------