-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit from GitHub Actions (Generate Site)
- Loading branch information
Showing
10 changed files
with
7,776 additions
and
7,385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
<!DOCTYPE html> | ||
<!--[if IE]><![endif]--> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Delete inactive Guest User | PnP Samples </title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" "=""> | ||
<meta name="title" content="Delete inactive Guest User | PnP Samples "> | ||
<meta name="generator" content="docfx 2.56.7.0"> | ||
<meta name="description" content="A sample gallery of scripts to manage all things Microsoft 365."> | ||
|
||
<!-- Social Media --> | ||
<meta property="og:locale" content="en_GB"> | ||
<meta property="og:title" content="Delete inactive Guest User | PnP Samples "> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:url" content="https://pnp.github.io/script-samples"> | ||
<meta property="og:image" content="https://pnp.github.io/script-samples/assets/social-media-screenshot.png"> | ||
<meta property="og:image:alt" content="Screenshot example of the PnP Script Samples Site"> | ||
<meta property="og:site_name" content="PnP Script Samples"> | ||
<meta name="msvalidate.01" content="04EFEDA66EC42C08A1247C979E2F9ADD"> | ||
<meta property="og:description" content="A sample gallery of scripts to manage all things Microsoft 365."> | ||
|
||
<link rel="shortcut icon" href="https://c.s-microsoft.com/favicon.ico?v2"> | ||
<link rel="stylesheet" href="../styles/docfx.vendor.css"> | ||
<link rel="stylesheet" href="../styles/docfx.css"> | ||
<link rel="stylesheet" href="../styles/main.css"> | ||
<link rel="stylesheet" href="../styles/extra.css"> | ||
<link rel="stylesheet" href="../styles/filter.css"> | ||
<link rel="stylesheet" href="../styles/site.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | ||
<meta property="docfx:navrel" content="../toc.html"> | ||
<meta property="docfx:tocrel" content="../toc.html"> | ||
|
||
|
||
<meta property="docfx:newtab" content="true"> | ||
<script type="text/javascript"> | ||
(function(c,l,a,r,i,t,y){ | ||
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; | ||
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; | ||
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); | ||
})(window, document, "clarity", "script", "8j6pedl344"); | ||
</script> | ||
</head> <body data-spy="scroll" data-target="#affix" data-offset="120"> | ||
<div id="wrapper"> | ||
<header> | ||
|
||
<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation"> | ||
<div class="container"> | ||
<div class="github-mark"> | ||
<a href="https://github.com/pnp/script-samples" title="Go to repository"> | ||
<div class="github-wrapper"> | ||
<div class="github-icon"> | ||
<img src="https://pnp.github.io/script-samples/assets/icons/github-light-64px.png" alt="GitHub Icon Image"> | ||
</div> | ||
<div class="github-repository"> | ||
<span>GitHub</span> | ||
<ul class="github-facts"> | ||
<li> | ||
<i class="fa fa-code-fork" aria-hidden="true"></i> | ||
<span class="github-forks"></span> | ||
</li> | ||
<li> | ||
<i class="fa fa-star-o" aria-hidden="true"></i> | ||
<span class="github-stars"></span> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</a> | ||
</div> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="../index.html"> | ||
<img id="logo" class="svg" src="../assets/logo.svg" alt=""> | ||
</a> </div> | ||
<div class="collapse navbar-collapse" id="navbar"> | ||
<form class="navbar-form navbar-right" role="search" id="search"> | ||
<div class="form-group"> | ||
<label class="glyphicon glyphicon-search" for="search-query"></label> | ||
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off"> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</nav> </header> | ||
<div role="main" class="container body-content hide-when-search"> | ||
<div class="article row grid"> | ||
<div class="col-md-12"> | ||
<article class="content wrap" id="_content" data-uid=""> | ||
<div class="contribution-panel mobile-hide pull-right"> | ||
<a href="https://github.com/pnp/script-samples/blob/main/scripts/aad-inactive-guest-delete/README.md/#L1" title="Improve this Doc" class="improve-doc-lg"><i class="glyphicon glyphicon-pencil"></i></a> | ||
</div> | ||
<h1 id="delete-inactive-guest-user">Delete inactive Guest User</h1> | ||
|
||
<p>The script will report inactive users for x days and provides an option to delete them.</p> | ||
<h2 id="summary">Summary</h2> | ||
<p>This PowerShell script identifies and optionally deletes inactive guest users in Microsoft 365. It connects to Microsoft Graph, retrieves guest users, checks their last sign-in date, and lists those who have been inactive for a specified number of days. The script then prompts the user to confirm whether to delete these inactive users.</p> | ||
<ul> | ||
<li>Open Windows PowerShell ISE or VS Code</li> | ||
<li>Copy script below to your clipboard</li> | ||
<li>Modify the $daysInactive variable as needed.</li> | ||
<li>Run the script to identify and optionally delete inactive guest users.</li> | ||
</ul> | ||
<div class="WARNING"> | ||
<h5>Warning</h5> | ||
<p>Please be aware this script contains a command that will remove or delete an artifact, ensure you test and understand the implications of running the script.</p> | ||
</div> | ||
<div class="tabGroup" id="tabgroup_CeZOj-G++Q"> | ||
<ul role="tablist"> | ||
<li role="presentation"> | ||
<a href="#tabpanel_CeZOj-G++Q_graphps" role="tab" aria-controls="tabpanel_CeZOj-G++Q_graphps" data-tab="graphps" tabindex="0" aria-selected="true">Microsoft Graph PowerShell</a> | ||
</li> | ||
</ul> | ||
<section id="tabpanel_CeZOj-G++Q_graphps" role="tabpanel" data-tab="graphps"><button class="article-clipboard" title="Copy to clipboard" data-toggle="tooltip" data-placement="top" data-clipboard-target="section[id^='tabpanel'][data-tab='graphps'] pre"> | ||
<span class="glyphicon glyphicon-copy" aria-hidden="true"></span> | ||
<span class="article-clipboard__message done">Copied</span> | ||
</button> | ||
|
||
<pre><code class="lang-powershell">#Install-Module Microsoft.Graph | ||
# Define the number of days of inactivity | ||
$daysInactive = 30 | ||
|
||
Connect-MgGraph -Scopes "User.Read.All", "User.ReadWrite.All","AuditLog.Read.All" | ||
|
||
$calcDate = (Get-Date).AddDays($daysInactive * -1) | ||
|
||
$guestUsers = Get-MgUser -Filter "userType eq 'Guest'" -All -Property id,displayName,mail,signInActivity,UserPrincipalName | ||
|
||
$inactiveUsers = @() | ||
|
||
foreach ($user in $guestUsers) { | ||
if ($user.SignInActivity.LastSignInDateTime -ge $calcDate) { | ||
$inactiveUsers += $user | ||
} | ||
} | ||
|
||
if ($inactiveUsers.Count -gt 0) { | ||
Write-Host "The following guest users have been inactive for $daysInactive days or more:" | ||
$inactiveUsers | ForEach-Object { | ||
Write-Host "$($_.DisplayName) ($($_.UserPrincipalName))" | ||
} | ||
|
||
# Ask if the user wants to delete the inactive users | ||
$delete = Read-Host "Do you want to delete these users? (y/n)" | ||
if ($delete -eq 'y') { | ||
$inactiveUsers | ForEach-Object { | ||
Remove-MgUser -UserId $_.Id -Confirm:$false | ||
Write-Host "Deleted user: $($_.DisplayName) ($($_.UserPrincipalName))" | ||
} | ||
} | ||
} else { | ||
Write-Host "No inactive guest users found." | ||
} | ||
|
||
|
||
Disconnect-MgGraph | ||
</code></pre> | ||
<div class="highlight-tool"> | ||
<p>Check out the <strong>Microsoft Graph PowerShell SDK</strong> to learn more at: <a href="https://learn.microsoft.com/graph/powershell/get-started">https://learn.microsoft.com/graph/powershell/get-started</a></p> | ||
</div> | ||
</section> | ||
</div> | ||
<h2 id="contributors">Contributors</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Author(s)</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><a href="https://github.com/petkir">Peter Paul Kirschner</a></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<h2 id="disclaimer">Disclaimer</h2> | ||
<p><strong>THESE SAMPLES ARE PROVIDED <em>AS IS</em> WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.</strong></p> | ||
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/aad-inactive-guest-delete" aria-hidden="true"> | ||
</article> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<footer> | ||
<div class="grad-bottom"></div> | ||
<div class="footer"> | ||
<div class="container"> | ||
<span class="pull-right"> | ||
<a href="#top">Back to top</a> | ||
</span> | ||
<span>Script Samples<br>Generated by <strong><a href='https://dotnet.github.io/docfx' alt='Doc FX Website'>DocFX</a></strong> with <strong><a href='https://ovasquez.github.io/docfx-material' alt='DocFx Material Theme'>Material UI</a></strong></span> | ||
|
||
<!-- <img src="https://telemetry.sharepointpnp.com/@pnp.github.io/index/" alt="spacer"> --> | ||
</div> | ||
</div> | ||
</footer> </div> | ||
|
||
<script type="text/javascript" src="../styles/docfx.vendor.js"></script> | ||
<script type="text/javascript" src="../styles/docfx.js"></script> | ||
<script type="text/javascript" src="../styles/main.js"></script> | ||
|
||
<script type="text/javascript" src="../styles/clipboard.min.js"></script> | ||
<script type="text/javascript" src="../styles/isotope.pkgd.min.js"></script> | ||
<script type="text/javascript" src="../styles/loadsamples.js"></script> | ||
<script type="text/javascript" src="../styles/filtersamples.js"></script> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[ | ||
{ | ||
"name": "aad-inactive-guest-delete", | ||
"source": "pnp", | ||
"title": "Delete inactive Guest User", | ||
"shortDescription": "The script will report inactive users for x days and provides an option to delete them.", | ||
"url": "https://pnp.github.io/script-samples/aad-inactive-guest-delete/README.html", | ||
"longDescription": [ | ||
"" | ||
], | ||
"creationDateTime": "2024-10-02", | ||
"updateDateTime": "2024-10-02", | ||
"products": [ | ||
"Graph" | ||
], | ||
"metadata": [ | ||
{ | ||
"key": "GRAPH-POWERSHELL", | ||
"value": "1.0.0" | ||
}, | ||
{ | ||
"key": "POWERSHELL", | ||
"value": "7.2.0" | ||
} | ||
], | ||
"categories": [ | ||
"Security" | ||
], | ||
"tags": [ | ||
"Get-MgUser", | ||
"Remove-MgUser" | ||
], | ||
"thumbnails": [ | ||
{ | ||
"type": "image", | ||
"order": 100, | ||
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/aad-inactive-guest-delete/assets/preview.png", | ||
"alt": "Preview of the sample Delete inactive Guest User" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"gitHubAccount": "petkir", | ||
"company": "ACP CUBIDO Digital Solutions GmbH", | ||
"pictureUrl": "https://github.com/petkir.png", | ||
"name": "Peter Paul Kirschner" | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"name": "Want to learn more about Microsoft Graph PowerShell SDK and the cmdlets", | ||
"description": "Check out the Microsoft Graph PowerShell SDK documentation site to get started and for the reference to the cmdlets.", | ||
"url": "https://learn.microsoft.com/graph/powershell/get-started" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.