<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anthony Buhnerkemper</title>
    <description>The latest articles on DEV Community by Anthony Buhnerkemper (@anthonybuhnerkemper).</description>
    <link>https://dev.to/anthonybuhnerkemper</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4176081%2F5d0fd606-e5cf-412a-8fe4-6c2d1963e763.png</url>
      <title>DEV Community: Anthony Buhnerkemper</title>
      <link>https://dev.to/anthonybuhnerkemper</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anthonybuhnerkemper"/>
    <language>en</language>
    <item>
      <title>Govern Power Platform with PowerShell 7: Environments, DLP, Orphaned Apps and Flows</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:59:09 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/govern-power-platform-with-powershell-7-environments-dlp-orphaned-apps-and-flows-1pfo</link>
      <guid>https://dev.to/anthonybuhnerkemper/govern-power-platform-with-powershell-7-environments-dlp-orphaned-apps-and-flows-1pfo</guid>
      <description>&lt;p&gt;Power Platform grows fast.&lt;/p&gt;

&lt;p&gt;One day you have a few apps. The next day you have hundreds of apps and flows, and nobody knows who owns them.&lt;/p&gt;

&lt;p&gt;The admin center is fine for one environment. For the whole tenant, I want a CSV.&lt;/p&gt;

&lt;p&gt;There is a catch. The Power Apps admin module only runs on Windows PowerShell 5.1. I wanted PowerShell 7.&lt;/p&gt;

&lt;p&gt;So I built a toolkit that calls the Power Platform admin APIs straight from PowerShell 7. It runs on Windows, macOS and Linux. I shared it on GitHub.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/power-platform-admin-powershell-toolkit" rel="noopener noreferrer"&gt;power-platform-admin-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Someone leaves the company. Their flows keep running as a deleted user, until they quietly fail.&lt;/p&gt;

&lt;p&gt;A trial environment from last year still sits there. Nobody remembers why.&lt;/p&gt;

&lt;p&gt;You want to block a connector in DLP. You have no idea who uses it.&lt;/p&gt;

&lt;p&gt;Dataverse storage is almost full. Which environment is the big one?&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-PPOrphanedResourceReport.ps1
&lt;/h3&gt;

&lt;p&gt;Finds apps and flows whose owner is deleted or disabled in Entra ID. It checks every owner once through Microsoft Graph.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PPOrphanedResourceReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-PPDlpPolicyReport.ps1
&lt;/h3&gt;

&lt;p&gt;Lists every DLP policy and its Business, Non business and Blocked connectors. Most important, it flags environments with no DLP policy at all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PPDlpPolicyReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-PPConnectorUsageReport.ps1
&lt;/h3&gt;

&lt;p&gt;Every connection in every environment, with the connector tier. Premium and custom connectors stand out, so it doubles as a license check.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PPConnectorUsageReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PremiumOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-PPTenantSettingsReport.ps1
&lt;/h3&gt;

&lt;p&gt;Exports all tenant settings to JSON and CSV. Then it checks key settings against a simple baseline. For example, can only admins create environments?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PPTenantSettingsReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover the environment inventory, Dataverse storage per environment, app and flow inventories, a makers report, and giving orphaned apps a new owner from a CSV.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;No Windows only modules. Sign in uses Az.Accounts, then the scripts call the admin APIs.&lt;/li&gt;
&lt;li&gt;Comment based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Every report is read only.&lt;/li&gt;
&lt;li&gt;The owner change script supports &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app only) or interactive sign in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;Once a month, I run the environment inventory and clean up old trials.&lt;/p&gt;

&lt;p&gt;Then I run the orphaned report and send it to the business. Someone has to take over those apps and flows.&lt;/p&gt;

&lt;p&gt;Before any DLP change, I run the connector usage report. Then I can warn the right makers first.&lt;/p&gt;

&lt;p&gt;Last, I export tenant settings and compare them with last month.&lt;/p&gt;

&lt;p&gt;One tip. For app only runs, register your app as a Power Platform management app first. Without that step, every call returns access denied.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/power-platform-admin-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; power-platform-admin-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. This one adds a PowerPlatform option. Dot source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;PowerPlatform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt;

&lt;span class="c1"&gt;# Or app only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;PowerPlatform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>powerplatform</category>
      <category>microsoft365</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Patch Azure VMs and Arc Servers with PowerShell 7 and Azure Update Manager</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:26:33 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/patch-azure-vms-and-arc-servers-with-powershell-7-and-azure-update-manager-h65</link>
      <guid>https://dev.to/anthonybuhnerkemper/patch-azure-vms-and-arc-servers-with-powershell-7-and-azure-update-manager-h65</guid>
      <description>&lt;p&gt;Patching is the job nobody thanks you for.&lt;/p&gt;

&lt;p&gt;Until a server misses a security update. Then everyone asks why.&lt;/p&gt;

&lt;p&gt;Azure Update Manager can patch Azure VMs and on premises servers through Azure Arc. The portal is fine for one machine. For fifty, I want a CSV.&lt;/p&gt;

&lt;p&gt;So I cleaned up the checks I use and shared them on GitHub. This toolkit uses PowerShell 7, the Az modules and Azure Resource Graph.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/azure-update-manager-powershell-toolkit" rel="noopener noreferrer"&gt;azure-update-manager-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;An Arc server goes quiet, and nobody notices until patch night.&lt;/p&gt;

&lt;p&gt;A security team asks "are we patched for this KB?" and you have to click through every machine.&lt;/p&gt;

&lt;p&gt;A VM is not on any patch schedule, so it never gets updates.&lt;/p&gt;

&lt;p&gt;The morning after patching, you need to know what failed. Fast.&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-AzUpdateComplianceSummary.ps1
&lt;/h3&gt;

&lt;p&gt;One row per machine with Critical, Security and Other update counts. It also shows a pending reboot and flags old assessments. One Resource Graph query covers every subscription.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzUpdateComplianceSummary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;MaxAssessmentAgeDays&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzPendingUpdateReport.ps1
&lt;/h3&gt;

&lt;p&gt;Every missing update on every machine. Filter by classification or by KB number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzPendingUpdateReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;KbId&lt;/span&gt; &lt;span class="mi"&gt;5000000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzMaintenanceScheduleReport.ps1
&lt;/h3&gt;

&lt;p&gt;Lists your patch schedules and which machine is on which one. Most important, it lists machines with no schedule at all.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzMaintenanceScheduleReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzUpdateInstallationHistory.ps1
&lt;/h3&gt;

&lt;p&gt;The morning after report. It shows each run with installed, failed and pending counts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzUpdateInstallationHistory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Days&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;FailedOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover Arc server health, failed Arc extensions, on demand assessments, setting the VM patch mode that schedules need, and assigning machines to schedules from a CSV.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Assessments only scan. They never install or reboot.&lt;/li&gt;
&lt;li&gt;Certificate (app only) or interactive sign in for Azure.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a test subscription first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;Every Monday, I run the Arc inventory and the compliance summary.&lt;/p&gt;

&lt;p&gt;A few days before patch night, I check that every machine has a schedule.&lt;/p&gt;

&lt;p&gt;Test machines patch first. Production waits a few days.&lt;/p&gt;

&lt;p&gt;The morning after, I run the history report with &lt;code&gt;-FailedOnly&lt;/code&gt; and fix what broke.&lt;/p&gt;

&lt;p&gt;One tip. If scheduled patching skips an Azure VM, check the patch mode. It must be AutomaticByPlatform with the schedule bypass turned on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/azure-update-manager-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; azure-update-manager-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SubscriptionId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;AZ_SUBSCRIPTION_ID&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/azure-governance-powershell-toolkit" rel="noopener noreferrer"&gt;azure-governance-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/azure-backup-dr-powershell-toolkit" rel="noopener noreferrer"&gt;azure-backup-dr-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/active-directory-hybrid-powershell-toolkit" rel="noopener noreferrer"&gt;active-directory-hybrid-powershell-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>azure</category>
      <category>patching</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Azure Governance with PowerShell 7: Tags, Leftovers, Access and Policy in One Toolkit</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:26:03 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/azure-governance-with-powershell-7-tags-leftovers-access-and-policy-in-one-toolkit-nn4</link>
      <guid>https://dev.to/anthonybuhnerkemper/azure-governance-with-powershell-7-tags-leftovers-access-and-policy-in-one-toolkit-nn4</guid>
      <description>&lt;p&gt;Azure subscriptions get messy fast.&lt;/p&gt;

&lt;p&gt;A VM is deleted, but its disk stays. Nobody knows who owns a resource group. A former employee still shows up in the access list as "Identity not found".&lt;/p&gt;

&lt;p&gt;None of this breaks anything today. But it costs money, and it makes audits painful.&lt;/p&gt;

&lt;p&gt;So I cleaned up the checks I use and shared them on GitHub. This toolkit uses PowerShell 7 and the Az modules.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/azure-governance-powershell-toolkit" rel="noopener noreferrer"&gt;azure-governance-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Resources have no tags, so nobody knows who to ask.&lt;/p&gt;

&lt;p&gt;Unattached disks and idle public IPs add up on the bill.&lt;/p&gt;

&lt;p&gt;Role assignments pile up. Some point to accounts that no longer exist.&lt;/p&gt;

&lt;p&gt;Policy shows red, but nobody knows where to start.&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-AzMissingTagReport.ps1
&lt;/h3&gt;

&lt;p&gt;Checks every resource group for your required tags. Add &lt;code&gt;-IncludeResources&lt;/code&gt; to check every resource too. Then fix them in bulk with &lt;code&gt;Set-AzTagFromCsv.ps1&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzMissingTagReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;RequiredTag&lt;/span&gt; &lt;span class="nc"&gt;Owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CostCenter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Environment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzOrphanedResourceReport.ps1
&lt;/h3&gt;

&lt;p&gt;Lists unattached disks, old snapshots, unused NICs, unused public IPs and empty resource groups. Anything tagged &lt;code&gt;Keep = true&lt;/code&gt; is marked so you can skip it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzOrphanedResourceReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SnapshotAgeDays&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove-AzUnattachedDisk.ps1
&lt;/h3&gt;

&lt;p&gt;Deletes old unattached disks. With &lt;code&gt;-SnapshotFirst&lt;/code&gt; it takes a cheap snapshot first, just in case. It asks before every disk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Remove&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzUnattachedDisk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;MinAgeDays&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SnapshotFirst&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzRoleAssignmentReport.ps1
&lt;/h3&gt;

&lt;p&gt;Lists every role assignment and flags privileged roles, direct user assignments, guests and orphaned entries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzRoleAssignmentReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PrivilegedOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover a full resource inventory, removing orphaned role assignments, Azure Policy compliance and Azure Advisor recommendations.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in for Azure.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a test subscription first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;Once a month, I run the inventory, the missing tag report and the leftover report.&lt;/p&gt;

&lt;p&gt;I send the leftover list to the owners and wait a week. Then I clean up what nobody claims.&lt;/p&gt;

&lt;p&gt;Every quarter, I run the access review and keep the CSV for audits.&lt;/p&gt;

&lt;p&gt;One tip. Start Azure Policy in Audit mode. Switch to Deny only when the report is clean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/azure-governance-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; azure-governance-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SubscriptionId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;AZ_SUBSCRIPTION_ID&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/azure-backup-dr-powershell-toolkit" rel="noopener noreferrer"&gt;azure-backup-dr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>azure</category>
      <category>governance</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Azure Backup and Site Recovery with PowerShell 7: Find the Gaps Before You Need a Restore</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:25:32 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/azure-backup-and-site-recovery-with-powershell-7-find-the-gaps-before-you-need-a-restore-1jn2</link>
      <guid>https://dev.to/anthonybuhnerkemper/azure-backup-and-site-recovery-with-powershell-7-find-the-gaps-before-you-need-a-restore-1jn2</guid>
      <description>&lt;p&gt;Backups are easy to set up. They are also easy to forget about.&lt;/p&gt;

&lt;p&gt;Then someone needs a restore, and you find out a VM was never protected. Or the last good backup was two weeks ago.&lt;/p&gt;

&lt;p&gt;So I cleaned up the checks I use and shared them on GitHub. This toolkit uses PowerShell 7 and the Az.RecoveryServices module.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/azure-backup-dr-powershell-toolkit" rel="noopener noreferrer"&gt;azure-backup-dr-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;A new VM goes live. Nobody turns on backup.&lt;/p&gt;

&lt;p&gt;A backup job fails every night. The alert goes to a mailbox nobody reads.&lt;/p&gt;

&lt;p&gt;Soft delete is off. One bad click and the backups are gone.&lt;/p&gt;

&lt;p&gt;Site Recovery is set up, but nobody has ever run a test failover.&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-AzUnprotectedVmReport.ps1
&lt;/h3&gt;

&lt;p&gt;Compares every VM in the subscription with every vault. It lists the VMs with no backup. VMs tagged &lt;code&gt;Backup = Exempt&lt;/code&gt; are listed as exempt, so you can document why they are skipped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzUnprotectedVmReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzBackupProtectedItemReport.ps1
&lt;/h3&gt;

&lt;p&gt;Shows every protected VM with its last backup result and how many hours ago it ran. It flags failed and stale backups.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzBackupProtectedItemReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;StaleHours&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzBackupVaultReport.ps1
&lt;/h3&gt;

&lt;p&gt;Checks each vault for soft delete, storage redundancy and immutability. These settings are your best defense against ransomware and mistakes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzBackupVaultReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AzSiteRecoveryHealthReport.ps1
&lt;/h3&gt;

&lt;p&gt;Shows replication health, RPO and test failover state for every replicated item. It flags anything that has never had a test failover.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AzSiteRecoveryHealthReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;MaxRpoMinutes&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover backup policies, failed jobs, restore points, turning on backup from a CSV and on-demand backups before a change.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in for Azure.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a test subscription first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I run the job report and the protected item report every morning. It takes a minute.&lt;/p&gt;

&lt;p&gt;Once a month, I run the gap report. Every VM should be protected or tagged as exempt.&lt;/p&gt;

&lt;p&gt;Before a risky change, I take an on-demand backup. It costs little and saves a lot.&lt;/p&gt;

&lt;p&gt;One tip. Do a real test restore at least once a quarter. A backup you have never restored is a hope, not a plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/azure-backup-dr-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; azure-backup-dr-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SubscriptionId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;AZ_SUBSCRIPTION_ID&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>azure</category>
      <category>backup</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Azure Virtual Desktop with PowerShell 7: Host Health, Sessions and Safe Restarts</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:25:00 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/azure-virtual-desktop-with-powershell-7-host-health-sessions-and-safe-restarts-hao</link>
      <guid>https://dev.to/anthonybuhnerkemper/azure-virtual-desktop-with-powershell-7-host-health-sessions-and-safe-restarts-hao</guid>
      <description>&lt;p&gt;I spent a lot of my career running virtual desktops for MSP clients. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;Azure Virtual Desktop is easy to stand up. Keeping it healthy day to day is the harder part.&lt;/p&gt;

&lt;p&gt;So I cleaned up the checks I use and shared them on GitHub. This toolkit uses PowerShell 7 and the Az.DesktopVirtualization module.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/azure-virtual-desktop-powershell-toolkit" rel="noopener noreferrer"&gt;azure-virtual-desktop-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;A host gets left in drain mode after patching. Nobody notices until the other hosts are full.&lt;/p&gt;

&lt;p&gt;A disconnected session holds a profile lock. The user can't sign in, and the ticket says "AVD is broken."&lt;/p&gt;

&lt;p&gt;Pools run all night with no scaling plan. The bill shows it.&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-AvdSessionHostReport.ps1
&lt;/h3&gt;

&lt;p&gt;Checks every session host in every pool. It flags hosts that are unavailable, stuck in drain mode, missing heartbeats or failing health checks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AvdSessionHostReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;HeartbeatMinutes&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove-AvdDisconnectedSession.ps1
&lt;/h3&gt;

&lt;p&gt;Signs out disconnected sessions older than a set number of hours. You can exclude accounts. Always run with &lt;code&gt;-WhatIf&lt;/code&gt; first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Remove&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AvdDisconnectedSession&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ResourceGroupName&lt;/span&gt; &lt;span class="n"&gt;rg&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;avd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;prod&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;HostPoolName&lt;/span&gt; &lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pooled&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;OlderThanHours&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Restart-AvdSessionHost.ps1
&lt;/h3&gt;

&lt;p&gt;Drains a host, skips it if users are still on it, restarts the VM and waits for it to come back. Then it turns drain mode off. If the host does not come back, it stays drained.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AvdSessionHost&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ResourceGroupName&lt;/span&gt; &lt;span class="n"&gt;rg&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;avd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;prod&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;HostPoolName&lt;/span&gt; &lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pooled&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SessionHostName&lt;/span&gt; &lt;span class="n"&gt;avd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-AvdScalingPlanReport.ps1
&lt;/h3&gt;

&lt;p&gt;Lists your scaling plans and their schedules. It also lists every host pool with no scaling plan turned on. That is where the savings are.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AvdScalingPlanReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover an environment inventory, finding a user's session, messaging users, drain mode and app group access reviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in for Azure.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a test subscription or a validation host pool first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I run the session host report every morning. It takes seconds.&lt;/p&gt;

&lt;p&gt;Before patching, I drain the host and send users a message. Once it is empty, I run the restart script. Then I run the report again to make sure every host is back.&lt;/p&gt;

&lt;p&gt;One tip. Set up a small validation host pool. It gets AVD agent updates first, so you catch problems before your users do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/azure-virtual-desktop-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; azure-virtual-desktop-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SubscriptionId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;AZ_SUBSCRIPTION_ID&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/citrix-powershell-toolkit" rel="noopener noreferrer"&gt;citrix-powershell-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>azure</category>
      <category>avd</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Hybrid Active Directory with PowerShell 7: Stale Accounts, Replication and Entra Connect Sync</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:24:23 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/hybrid-active-directory-with-powershell-7-stale-accounts-replication-and-entra-connect-sync-2kdg</link>
      <guid>https://dev.to/anthonybuhnerkemper/hybrid-active-directory-with-powershell-7-stale-accounts-replication-and-entra-connect-sync-2kdg</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;Most tenants I have seen are still hybrid. Users live in on-prem Active Directory and sync to Entra ID. So the cloud is only as clean as AD.&lt;/p&gt;

&lt;p&gt;I kept writing the same AD and sync checks. So I cleaned them up and shared them on GitHub. This toolkit uses PowerShell 7, the RSAT ActiveDirectory module, the ADSync module and Microsoft Graph.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/active-directory-hybrid-powershell-toolkit" rel="noopener noreferrer"&gt;active-directory-hybrid-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Old accounts pile up in AD. Nobody is sure who is really in Domain Admins.&lt;/p&gt;

&lt;p&gt;Sync breaks quietly. A duplicate email alias blocks one user, and you find out when they call.&lt;/p&gt;

&lt;p&gt;These scripts make those checks quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-ADStaleAccountReport.ps1
&lt;/h3&gt;

&lt;p&gt;Finds enabled users and computers that have not logged on in a number of days. You can skip OUs like service accounts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ADStaleAccountReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DaysInactive&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ExcludeOU&lt;/span&gt; &lt;span class="s1"&gt;'OU=Service Accounts,DC=contoso,DC=com'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Disable-ADStaleAccount.ps1
&lt;/h3&gt;

&lt;p&gt;Takes the reviewed CSV and disables each account. It stamps the description and can move it to a holding OU. Always run with &lt;code&gt;-WhatIf&lt;/code&gt; first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Disable&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ADStaleAccount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;CsvPath&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;reviewed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;TargetOU&lt;/span&gt; &lt;span class="s1"&gt;'OU=Disabled,DC=contoso,DC=com'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-ADPrivilegedGroupReport.ps1
&lt;/h3&gt;

&lt;p&gt;Expands nested members of Domain Admins and the other built-in admin groups. It flags stale admins and passwords that never expire.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ADPrivilegedGroupReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compare-ADEntraUser.ps1
&lt;/h3&gt;

&lt;p&gt;Matches AD users to their Entra ID accounts. It reports users that are not synced, UPNs that do not match, and enabled status that does not match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Compare&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ADEntraUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover password policy, replication health, Entra Connect sync status, starting a delta sync, sync errors and UPN readiness before you sync a new OU.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in for Graph.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a lab domain and a test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;One hybrid tip. If you move a disabled user out of your sync scope, the cloud account gets soft-deleted on the next sync. Plan for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/active-directory-hybrid-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; active-directory-hybrid-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AD scripts only need RSAT. For the cloud side, every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;GraphScopes&lt;/span&gt; &lt;span class="nc"&gt;Organization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Directory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and rights each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have more free toolkits that use the same pattern, including &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt; and &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>activedirectory</category>
      <category>azure</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>OneDrive for Business with PowerShell 7: Leavers, Sharing and Pre-Provisioning</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:23:53 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/onedrive-for-business-with-powershell-7-leavers-sharing-and-pre-provisioning-3f78</link>
      <guid>https://dev.to/anthonybuhnerkemper/onedrive-for-business-with-powershell-7-leavers-sharing-and-pre-provisioning-3f78</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for OneDrive for Business admins. It uses the SPO module and Microsoft Graph with PowerShell 7.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;When someone leaves, their manager often needs their files. Doing that by hand is fiddly.&lt;/p&gt;

&lt;p&gt;Users also share files with "anyone" links and forget about them.&lt;/p&gt;

&lt;p&gt;And before a migration, new users may not have a OneDrive yet. These scripts handle all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Grant-DepartedUserOneDriveAccess.ps1
&lt;/h3&gt;

&lt;p&gt;Gives a manager access to a leaver's OneDrive as a secondary admin. A matching script removes that access later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Grant&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DepartedUserOneDriveAccess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DepartedUser&lt;/span&gt; &lt;span class="n"&gt;former&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;@&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Delegate&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt;@&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-OneDriveSharingAudit.ps1
&lt;/h3&gt;

&lt;p&gt;Lists shared files and folders per user with the link type. Use &lt;code&gt;-AnonymousOnly&lt;/code&gt; to see just the "anyone" links.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;OneDriveSharingAudit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;UserPrincipalName&lt;/span&gt; &lt;span class="n"&gt;user1&lt;/span&gt;@&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AnonymousOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Request-OneDrivePreProvisioning.ps1
&lt;/h3&gt;

&lt;p&gt;Pre-provisions OneDrive for licensed users who never signed in. Handy before a file migration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;OneDrivePreProvisioning&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;CsvPath&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;preprovision&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover OneDrive inventory and storage, usage reports and tenant settings. The docs include Known Folder Move notes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; onedrive-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;SharePoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;SharePoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
    <item>
      <title>Microsoft Purview with PowerShell 7: DLP Rollout, Audit Search and eDiscovery</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:23:18 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/microsoft-purview-with-powershell-7-dlp-rollout-audit-search-and-ediscovery-2984</link>
      <guid>https://dev.to/anthonybuhnerkemper/microsoft-purview-with-powershell-7-dlp-rollout-audit-search-and-ediscovery-2984</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for Microsoft Purview. It uses PowerShell 7 and &lt;code&gt;Connect-IPPSSession&lt;/code&gt; from ExchangeOnlineManagement v3.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Compliance work is often slow and careful. You don't want to switch on DLP and block the whole company.&lt;/p&gt;

&lt;p&gt;Audit log searches in the portal time out or cap results. eDiscovery setup has many clicks.&lt;/p&gt;

&lt;p&gt;These scripts help you go step by step. They build on the Graph admin toolkit instead of copying it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Set-DlpPolicyMode.ps1
&lt;/h3&gt;

&lt;p&gt;Moves a DLP policy between simulation and enforcement. Start silent, then add notifications, then enforce.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DlpPolicyMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="s1"&gt;'Contoso - U.S. Financial Data'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Mode&lt;/span&gt; &lt;span class="nc"&gt;TestWithNotifications&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Search-AuditLogReport.ps1
&lt;/h3&gt;

&lt;p&gt;Searches the unified audit log and pages through large results. It flattens them to CSV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Search&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AuditLogReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Operations&lt;/span&gt; &lt;span class="nc"&gt;FileDownloaded&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;UserIds&lt;/span&gt; &lt;span class="n"&gt;user1&lt;/span&gt;@&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;StartDate&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddDays&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  New-EDiscoveryCaseSearch.ps1
&lt;/h3&gt;

&lt;p&gt;Creates or reuses an eDiscovery case and adds a search scoped to mailboxes or sites.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Help&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;New&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;EDiscoveryCaseSearch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Examples&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover label and auto-label policy reports, DLP rule matches, retention labels, eDiscovery case reports and insider risk policies.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/purview-compliance-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; purview-compliance-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Purview&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Purview&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
    <item>
      <title>Microsoft Sentinel Rules as Code with PowerShell 7 and KQL</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:22:43 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/microsoft-sentinel-rules-as-code-with-powershell-7-and-kql-32k4</link>
      <guid>https://dev.to/anthonybuhnerkemper/microsoft-sentinel-rules-as-code-with-powershell-7-and-kql-32k4</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for Microsoft Sentinel. It uses PowerShell 7, Az.SecurityInsights and KQL.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Analytics rules built in the portal are hard to track. Who changed what? Is there a backup?&lt;/p&gt;

&lt;p&gt;Data connectors can also stop sending data without much noise. Then your detections see nothing.&lt;/p&gt;

&lt;p&gt;This toolkit treats rules as code. It also checks that data still flows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Export-SentinelAnalyticsRule.ps1
&lt;/h3&gt;

&lt;p&gt;Exports analytics rules to JSON, one file per rule. Put them in Git for backup and review.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Export&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SentinelAnalyticsRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt; &lt;span class="nc"&gt;Scheduled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  New-SentinelRuleFromKql.ps1
&lt;/h3&gt;

&lt;p&gt;Creates or updates a Scheduled rule from a &lt;code&gt;.kql&lt;/code&gt; file. Each detection has a metadata header. Samples include MFA fatigue, new Global Admin and brute force success.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;New&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SentinelRuleFromKql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;KqlFile&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;detections&lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kql&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-SentinelDataConnectorHealth.ps1
&lt;/h3&gt;

&lt;p&gt;Checks connectors and the last record per table. It flags tables that have gone quiet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;SentinelDataConnectorHealth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;StaleHours&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover rule import, a rule report, an incident report and a KQL query runner. The docs include workbook notes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; sentinel-kql-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Azure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
    <item>
      <title>Defender XDR with PowerShell 7: Advanced Hunting from the Command Line</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:22:10 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/defender-xdr-with-powershell-7-advanced-hunting-from-the-command-line-2fj0</link>
      <guid>https://dev.to/anthonybuhnerkemper/defender-xdr-with-powershell-7-advanced-hunting-from-the-command-line-2fj0</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for Microsoft Defender XDR. It uses PowerShell 7 and the Microsoft Graph security API, including &lt;code&gt;runHuntingQuery&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;The Defender portal is great for one incident. It is less great for reports, trends or running the same hunt every week.&lt;/p&gt;

&lt;p&gt;You also want to know which devices are not onboarded to Defender for Endpoint. Gaps there are blind spots.&lt;/p&gt;

&lt;p&gt;These scripts pull that data to CSV so you can track it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Invoke-AdvancedHuntingQuery.ps1
&lt;/h3&gt;

&lt;p&gt;Runs an advanced hunting KQL query and exports the results. The repo has a small KQL library, like encoded PowerShell, password spray and new forwarding rules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AdvancedHuntingQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;QueryFile&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;hunting&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;queries&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;encoded&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;powershell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kql&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AdvancedHuntingQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Query&lt;/span&gt; &lt;span class="s1"&gt;'DeviceInfo | summarize count() by OSPlatform'&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;PassThru&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-MDEOnboardingStatus.ps1
&lt;/h3&gt;

&lt;p&gt;Compares Intune Windows devices with Defender for Endpoint. It shows devices that are not onboarded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;MDEOnboardingStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-DefenderIncidentReport.ps1
&lt;/h3&gt;

&lt;p&gt;Exports incidents with alert counts for a time window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DefenderIncidentReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Days&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover alert reports, device risk, Secure Score and setting incident status. Sample KQL is a starting point, so tune it first.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; defender-xdr-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
    <item>
      <title>Intune with PowerShell 7: Compliance, Stale Devices and Autopilot</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:21:29 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/intune-with-powershell-7-compliance-stale-devices-and-autopilot-3a93</link>
      <guid>https://dev.to/anthonybuhnerkemper/intune-with-powershell-7-compliance-stale-devices-and-autopilot-3a93</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for Microsoft Intune admins. It uses PowerShell 7 and the Microsoft.Graph SDK v2. Beta-only endpoints use &lt;code&gt;Invoke-MgGraphRequest&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Device lists get messy. Old laptops never check in again. Compliance reports in the portal are hard to export.&lt;/p&gt;

&lt;p&gt;Autopilot imports by hand are slow when a box of new devices arrives.&lt;/p&gt;

&lt;p&gt;These scripts make those jobs quick and repeatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-IntuneComplianceReport.ps1
&lt;/h3&gt;

&lt;p&gt;Gives per-policy status counts and a list of non-compliant devices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;IntuneComplianceReport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove-IntuneStaleDevice.ps1
&lt;/h3&gt;

&lt;p&gt;Retires or deletes devices that have not checked in for a number of days. You can filter by OS. Always run with &lt;code&gt;-WhatIf&lt;/code&gt; first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Remove&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;IntuneStaleDevice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DaysInactive&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Remove&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;IntuneStaleDevice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;DaysInactive&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Action&lt;/span&gt; &lt;span class="nc"&gt;Delete&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;OperatingSystem&lt;/span&gt; &lt;span class="nc"&gt;Android&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Confirm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Import-AutopilotDevice.ps1
&lt;/h3&gt;

&lt;p&gt;Imports Autopilot devices from a hardware hash CSV. You can set a group tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Import&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;AutopilotDevice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;CsvPath&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;autopilot&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hashes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;GroupTag&lt;/span&gt; &lt;span class="nc"&gt;Contoso&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Standard&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover device inventory, device sync, app deployment status, Autopilot reports and configuration profile export.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/intune-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; intune-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
    <item>
      <title>Microsoft Teams with PowerShell 7: Find and Fix Orphaned Teams</title>
      <dc:creator>Anthony Buhnerkemper</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:21:00 +0000</pubDate>
      <link>https://dev.to/anthonybuhnerkemper/microsoft-teams-with-powershell-7-find-and-fix-orphaned-teams-20ak</link>
      <guid>https://dev.to/anthonybuhnerkemper/microsoft-teams-with-powershell-7-find-and-fix-orphaned-teams-20ak</guid>
      <description>&lt;p&gt;I have worked in IT for about 20 years. A lot of that was MSP operations. Today I work as an M365 cloud admin.&lt;/p&gt;

&lt;p&gt;I kept writing the same scripts. So I cleaned them up and shared them on GitHub. This toolkit is for Microsoft Teams admins. It uses PowerShell 7 and the MicrosoftTeams module 6.x.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/anthonybuhnerkemper/teams-powershell-toolkit" rel="noopener noreferrer"&gt;teams-powershell-toolkit&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem it solves
&lt;/h2&gt;

&lt;p&gt;Teams sprawl is real. Owners leave and teams end up with nobody in charge. Guests pile up.&lt;/p&gt;

&lt;p&gt;A team with no owner can't approve members or manage settings. Someone has to fix it.&lt;/p&gt;

&lt;p&gt;These scripts find the gaps and help you fix them in bulk.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlight scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Get-OrphanedTeams.ps1
&lt;/h3&gt;

&lt;p&gt;Finds teams with no owner, or fewer owners than you want. The default is two.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;OrphanedTeams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add-TeamOwnerToOrphanedTeam.ps1
&lt;/h3&gt;

&lt;p&gt;Takes the CSV from the report above and adds an owner to each team.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;TeamOwnerToOrphanedTeam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;CsvPath&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;OrphanedTeams&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20260101&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0900&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;csv&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Owner&lt;/span&gt; &lt;span class="n"&gt;teams&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;admin&lt;/span&gt;@&lt;span class="n"&gt;contoso&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;WhatIf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get-TeamsOwnerGuestAudit.ps1
&lt;/h3&gt;

&lt;p&gt;Lists owners and guests for every team, one row per person. Use &lt;code&gt;-GuestsOnly&lt;/code&gt; for a guest review.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;TeamsOwnerGuestAudit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;GuestsOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other scripts cover team inventory, policy assignment from CSV, policy reports, Teams Phone basics and bulk channel creation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the scripts are built
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell 7.4 or later.&lt;/li&gt;
&lt;li&gt;Comment-based help on every script. Run &lt;code&gt;Get-Help ./script.ps1 -Full&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Reports export to CSV.&lt;/li&gt;
&lt;li&gt;Change scripts support &lt;code&gt;-WhatIf&lt;/code&gt; and &lt;code&gt;-Confirm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Certificate (app-only) or interactive sign-in.&lt;/li&gt;
&lt;li&gt;No secrets in the repo. Examples use &lt;code&gt;contoso.com&lt;/code&gt; and placeholder GUIDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please test in a dev or test tenant first. Read each script before you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  My usual workflow
&lt;/h2&gt;

&lt;p&gt;I start with the reports. They are read-only and safe. I open the CSV in Excel and look for anything odd.&lt;/p&gt;

&lt;p&gt;Then I pick one fix. I run the change script with &lt;code&gt;-WhatIf&lt;/code&gt; and read the output. If it looks right, I run it again for real.&lt;/p&gt;

&lt;p&gt;For jobs I repeat, I use a certificate and schedule the script. That way nobody has to remember to run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anthonybuhnerkemper/teams-powershell-toolkit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; teams-powershell-toolkit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every toolkit ships the same &lt;code&gt;Connect-M365Admin&lt;/code&gt; script. Dot-source it, then connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Interactive sign-in&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scripts&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Teams&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Interactive&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ClientId&lt;/span&gt; &lt;span class="mi"&gt;00000000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0000&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;000000000000&lt;/span&gt;

&lt;span class="c1"&gt;# Or app-only with a certificate&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_TENANT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CLIENT_ID&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'00000000-0000-0000-0000-000000000000'&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;M365_CERT_THUMBPRINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0000000000000000000000000000000000000000'&lt;/span&gt;
&lt;span class="nc"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;M365Admin&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="nc"&gt;Teams&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a report, check the CSV, then call &lt;code&gt;Disconnect-M365Admin&lt;/code&gt; when you are done. The README lists the modules and roles each script needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  More toolkits
&lt;/h2&gt;

&lt;p&gt;I have nine more free toolkits that use the same pattern: &lt;a href="https://github.com/anthonybuhnerkemper/graph-powershell7-admin-toolkit" rel="noopener noreferrer"&gt;graph-powershell7-admin-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/entra-id-powershell-toolkit" rel="noopener noreferrer"&gt;entra-id-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/exchange-online-powershell-toolkit" rel="noopener noreferrer"&gt;exchange-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sharepoint-online-powershell-toolkit" rel="noopener noreferrer"&gt;sharepoint-online-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/onedrive-powershell-toolkit" rel="noopener noreferrer"&gt;onedrive-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/intune-powershell-toolkit" rel="noopener noreferrer"&gt;intune-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/defender-xdr-powershell-toolkit" rel="noopener noreferrer"&gt;defender-xdr-powershell-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/sentinel-kql-toolkit" rel="noopener noreferrer"&gt;sentinel-kql-toolkit&lt;/a&gt;, &lt;a href="https://github.com/anthonybuhnerkemper/purview-compliance-toolkit" rel="noopener noreferrer"&gt;purview-compliance-toolkit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find them all on my &lt;a href="https://github.com/anthonybuhnerkemper" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;Issues, ideas and pull requests are welcome. What would you add? Tell me in the comments.&lt;/p&gt;

</description>
      <category>powershell</category>
      <category>microsoft365</category>
      <category>azure</category>
      <category>security</category>
    </item>
  </channel>
</rss>
