Skip to content

Instantly share code, notes, and snippets.

@Fantasillion
Fantasillion / azuser IAM.ps1
Created June 17, 2024 10:08
Azure IAM non-inherited role assignments for currently selected subscription and resource groups and resources
# Connect and choose subscription
# connect-AzAccounts
# Initialize azusers as an array
$azusers = @()
# Get all resource groups
$resourceGroups = Get-AzResourceGroup
# Get all resources
@Fantasillion
Fantasillion / Windows Update Service remove KB and disable Service for 30 days.ps1
Last active August 9, 2023 12:59
Check for specific Windows KB, then Uninstall KB, Stop and Disable wuauserv, create scheduled task in 30 days to start and enable automatic wuauserv, reboot prompt
# Check if running as administrator
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$response = Read-Host "This script requires elevated permissions.
Do you want to run this script as an Administrator?
(y/n)"
if ($response -eq 'y') {
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
exit
} else {
"Exiting script." | Out-Host
@Fantasillion
Fantasillion / PRTG Close All Open Tickets Bulk Script.ps1
Created August 8, 2023 16:12
PRTG Close All Open Tickets Bulk Script
# Ensuring TLS/SSL connection to our host
# WARNING: TrustAllCertsPolicy trusts all SSL certificates, including invalid ones.
# Use this only if connecting to a server with a self-signed or untrusted certificate.
# For servers with valid SSL certificates from a trusted CA, consider removing this section.
#add-type @"
# using System.Net;
# using System.Security.Cryptography.X509Certificates;
# public class TrustAllCertsPolicy : ICertificatePolicy {
# public bool CheckValidationResult(
# ServicePoint srvPoint, X509Certificate certificate,
@Fantasillion
Fantasillion / Add Win 10 and Win 11 devices to separate Security Groups.ps1
Last active August 8, 2023 16:03
Add Win 10 and Win 11 devices to separate Security Groups
# Import the ActiveDirectory module
Import-Module ActiveDirectory
# Define the names of your groups
$win10Group = "Windows 10 Computers"
$win11Group = "Windows 11 Computers"
# Define the OU from where you want to get computer objects. Replace OU=Computers,DC=YourDomain,DC=com with your OU
$ou = "OU=Computers,DC=YourDomain,DC=com"
@Fantasillion
Fantasillion / Visual Studio 2022 Windows Defender Exclusions.ps1
Last active February 14, 2023 10:08
Visual Studio 2022 Windows Defender Exclusions.ps1
$userPath = $env:USERPROFILE
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null
$pathExclusions.Add('C:\Windows\assembly') > $null
$pathExclusions.Add($userPath + '\Downloads\HeidiSQL_11.3_64_Portable') > $null
$pathExclusions.Add($userPath + '\.dotnet') > $null
@Fantasillion
Fantasillion / Export Size and Status of Archive Mailbox for all Microsoft 365 users with gui view
Created February 9, 2023 12:15
Export Size and Status of Archive Mailbox for all Microsoft 365 users with gui view
$Result=@()
#Get all user mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox
$totalmbx = $mailboxes.Count
$i = 0
$mailboxes | ForEach-Object {
$i++
$mbx = $_
$size = $null
@Fantasillion
Fantasillion / Get Exchange Online Archive Last Run Status for each user
Created February 8, 2023 15:22
Get Exchange Online Archive Last Run Status for each user
$Mbx = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$Report = @()
ForEach ($M in $Mbx) {
$LastProcessed = $Null
Write-Host "Processing" $M.DisplayName
$Log = Export-MailboxDiagnosticLogs -Identity $M.Alias -ExtendedProperties
$xml = [xml]($Log.MailboxLog)
$LastProcessed = ($xml.Properties.MailboxTable.Property | ? {$_.Name -like "*ELCLastSuccessTimestamp*"}).Value
$ItemsArchived = $xml.Properties.MailboxTable.Property | ? {$_.Name -like "*ElcLastRunArchivedFromRootItemCount*"}
If ($LastProcessed -eq $Null) {
@Fantasillion
Fantasillion / Connect ExchangeOnline Powershell.ps1
Created October 28, 2022 11:17
Connect ExchangeOnline Powershell
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName <replace brackets and contents with the upn you want to connect with>
@Fantasillion
Fantasillion / Room Mailbox Calendar set LimitedDetails.ps1
Last active October 28, 2022 11:11
Room Mailbox Calendar set LimitedDetails
#Get list of all room mailboxes
Get-Mailbox -RecipientTypeDetails RoomMailbox | Select Name
#Get list of specific mailbox calendar access rights English:
Get-MailboxFolderPermission -Identity insert name of room:\Calendar
#Get list of specific mailbox calendar access rights Danish:
Get-MailboxFolderPermission -Identity insert name of room:\Kalender
#Adding view access rights for calendar room mailbox Danish
@Fantasillion
Fantasillion / Office 365 Exchange Online access rights on Calendars.ps1
Created October 28, 2022 11:02
Office 365 Exchange Online access rights on Calendars
#Note that the language chosen upon first login decides the naming used for the mailbox calendar.
#Change default rights Danish calendar:
foreach($user in Get-Mailbox -RecipientTypeDetails UserMailbox) {
$cal = $user.alias+":\Kalender"
Set-MailboxFolderPermission -Identity $cal -User Default -AccessRights LimitedDetails
}
#Change default rights English calendar:
foreach($user in Get-Mailbox -RecipientTypeDetails UserMailbox) {