Skip to content

Instantly share code, notes, and snippets.

@win2000b
win2000b / Disabled365Accounts_ExcludingSharedMailboxes.ps1
Created June 30, 2025 10:18
Find All disabled Users excluding Shared Mailboxes
# Step 1: Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
# Step 2: Get all disabled users from Microsoft Graph
$allUsers = Get-MgUser -All -Property "DisplayName,UserPrincipalName,AccountEnabled,CreatedDateTime"
$disabledUsers = $allUsers | Where-Object { $_.AccountEnabled -eq $false }
# Step 3: Connect to Exchange Online
Connect-ExchangeOnline
@win2000b
win2000b / Get-EntraSubordinates-WithManagerOnly.ps1
Created June 25, 2025 14:59
Find Manager Subordinates and recurse down
# Run with "powershell -ExecutionPolicy Bypass -File .\Get-EntraSubordinates-WithManagerOnly.ps1"
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All"
# Function to recursively retrieve all subordinates under a manager
function Get-SubordinatesRecursive {
param (
[string]$ManagerId,
[hashtable]$Visited,
@win2000b
win2000b / Detect and Remediate Windows Store.ps1
Created June 20, 2025 09:27
Intune Device Detect and Remediate - Windows Store App
<#
Type : Detection
Job: Detects Microsoft 3D Viewer
Run as: System
Context: 64 Bit
#>
# Replace with part or full name of the app package
$appName = "Microsoft.Microsoft3DViewer"
@win2000b
win2000b / Detect and Remediate.ps1
Last active June 20, 2025 09:26
Intune Device Detect and Remediate - Registry Key
<#
Type: Detection
Job: Detects Registry Key and if present or not
Run as: System
Context: 64 Bit
#>
# Define Varibles
$regPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client"
$regName = "AllowBasic"
@win2000b
win2000b / DisableBasicAuth.ps1
Last active June 20, 2025 09:21
Set Registry Key via Win32 App
# Sample Script for Win32 Application to set a reg key and monitor it.
$regPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client"
$valueName = "AllowBasic"
$desiredValue = 0
# Ensure the registry key exists
if (-not (Test-Path $regPath)) {
New-Item -Path $regPath -Force | Out-Null
}
@win2000b
win2000b / GetTeamsNumbers.ps1
Created April 14, 2022 10:52
Get List of Teams Numbers and export to CSV
# Install the Teams Module within PowerShell
Install-Module MicrosoftTeams
# Connect to Microsoft Teams PowerShell
Connect-MicrosoftTeams
#Get list of Users and export their details to csv
Get-CsOnlineUser -Filter {LineURI -ne $Null} | select DisplayName,LineURI,OnlineVoiceRoutingPolicy | Export-CSV c:\temp\teams.csv -NoTypeInformation
@win2000b
win2000b / Get-WindowsAutopilotinfo.ps1
Created November 9, 2020 15:28
Get AutoPilot Info Online
# At the OOBE, open a command prompt session. Shift F10
# Launch PowerShell
Powershell.exe
# Set PowerShell Execution Policy
Set-ExecutionPolicy bypass
# Install the AutoPilot Script
install-script get-windowsautopilotinfo
@win2000b
win2000b / Logon.ps1
Created October 16, 2020 15:27
Audit Logon / Logoff PowerShell
Param (
[string]$Computer = (Read-Host Remote computer name),
[int]$Days = 20
)
cls
$Result = @()
Write-Host "Gathering Event Logs, this can take awhile..."
$ELogs = Get-EventLog System -Source Microsoft-Windows-WinLogon -After (Get-Date).AddDays(-$Days) -ComputerName $Computer
If ($ELogs)
{ Write-Host "Processing..."
@win2000b
win2000b / RestartSearch.xml
Created September 16, 2020 07:41
Scheduled task to restart search service on WVD
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-09-15T15:31:06.0051067</Date>
<Author>DOMAIN\user</Author>
<URI>\Restart Windows Search Service</URI>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
@win2000b
win2000b / Removehold.ps1
Created August 10, 2020 08:48
Remove Holds and then query
$mailboxes = Get-Mailbox
foreach ($mailbox in $mailboxes)
{
set-mailbox $mailbox.Alias -removedelayholdapplied
set-mailbox $mailbox.Alias -removedelayreleaseholdapplied
}
$mailboxes = Get-Mailbox
foreach ($mailbox in $mailboxes)