Fun with PowerShell, Azure Automation and Microsoft Teams

I’m currently working on a solution at work which is ultimately a contribution to our process of trying to keep on top of our proof of concept environments usage of networking and in particular ip address ranges. We have a rolling set of Azure Virtual Networks that vary in size from a class C to the occasional class A when we have a silly scale HPC or Kubernetes CNI requirement for a gazillion addresses in a big subnet.

The solution is coming together in very small building blocks and this post is to provide me (and you interwebs folks) with a reference to the filter syntax for List all teams in Microsoft Teams using Microsoft Graph.

Although the automation method shouldn’t really matter for what is effectively a big REST API, you know how it is when you have to translate syntax and fiddle around with quotation marks and things. Anyway, to cut a long story short the rough PowerShell script for List all teams in Microsoft Teams in PowerShell is:

# PowerShell to list all teams in your tenant
# Assumes you have set up your certificate authentication
$appId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$tenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$cert = Get-AutomationCertificate -Name 'AzureAutomationCertificate'

# Magic we are doing needs beta apis for the filter to work
Select-MgProfile -Name "beta"

# Authenticate to MS Graph
Connect-MgGraph -ClientID $appId -TenantId $tenantId -Certificate $cert

# Get list of Teams i.e. Groups with the special resource provisioning options set
$teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')"
$teamscount = @($teams).Count
Write-Verbose "The number of teams is $teamscount" -Verbose

# Close Connection to MS Graph
Disconnect-MgGraph

A few caveats and notes

  • This isn’t a full working example, in my case I’m using Azure Automation Runbooks and they are very very particular about their outputs and object handling. I’m still working on my translation.
  • It assumes you have done the work to create a self-signed certificate, create the app registration, uploaded the certificate to the app registration *and* set it up in your automation account. (I might do a meta post on this as I found one blog post that had the wrong parameters for the cert generation and generated a cert file of format cer with a pfx extension…)
  • This is being written for an Azure Automation Account in PowerShell, remember to add the relevant modules that are needed. I was adding individual modules as I found them first but you will probably be quicker just using Microsoft.Graph – you will find it in the gallery. Otherwise for the above you will need Microsoft.Graph.Authentication, and Microsoft.Graph.Groups.
  • If your tenant is anything like ours then you will always get 100 as the count of teams, due to the way that the apis manage their output length.
  • The script doesn’t do anything useful but I thought it might help to see the filter syntax

References, Source Material and Inspiration

How life goes in circles

That a significant pointer would be found in a response on GitHub by Darrel Miller is quite fascinating. I met Darrel on the expo floor at Microsoft Ignite in Orlando in 2018 and only really because I was after some “Swag” and had to get a card stamped by various Product Managers and Architects on the Microsoft 365 stand. At the time I was up to my neck in Azure and trying my best to get away from SharePoint (and Microsoft 365) and my discussions with the people on those stands were all to try and get me to talk to Graph and get back in to SharePoint Development with the new SPFx thing.

So it’s taken me about 2 and a half years, but I’m finally getting there. Thankyou Darrel – check him out on twitter etc!

Passed DP-900: Microsoft Azure Fundamentals

I’m pleased to say that I recently passed DP-900: Microsoft Azure Fundamentals. If you’ve come to this post via the home page then you’ll see that I recently passed DP-200 and DP-201 to achieve the Certified Data Engineer certification and as I had a discount voucher with 50% off an exam I decided to do another fundamentals exam.

Microsoft Certified: Azure Data Fundamentals
DP-900 Badge

Although my employer hadn’t asked, I decided to go for the set as a qualification for the Microsoft Partner Data Platform Competency. It appears that Microsoft are shifting away from the technical assessments that were delivered through partner university. This makes a bit of sense now that there are obvious public certifications available and while being a little more difficult, the fundamentals is more of a useful achievement.

From a personal milestone this is my 40th Microsoft Exam pass; way back before OneNote was a thing I started an exam ritual of creating a folder for the next exam I was targeting. In the small development company that was the first Microsoft Partner I worked at we used presentation binders for training packs – basically a ring binder with pockets in the front and spine for labelling. I would go through the ritual of creating a front cover for the binder, with my name, exam and “volume” number. I still go through this exercise and they have slowly counted up over the last year and a bit. Now my “exam process” tends to focus around OneNote but I still have a set of pipeline folders which have files related to an exam prep.

Microsoft Certification as a thing has ebbed and flowed through the years. Like a lot of things early in my career I just simply something because my employer asked me to. They wanted to get Microsoft Gold Partner and needed employees who had certifications. Thus started my journey with my first exam pass on April 19th 1996 which at the time of me writing this post is 25 years ago. That was also just under a year before I got married, so my long suffering wife has been with me for my entire certification journey!