Skip to content

Instantly share code, notes, and snippets.

@nicolonsky
nicolonsky / OOO.kql
Created December 19, 2025 08:24
Your festive out of office message for auto-reply 🎄
// Paste into your favorite KQL engine such as Log Analytics / Sentinel / Defender / ADX
// https://aka.ms/kustofree
let AbsenceInfo = datatable
(
StartDate: datetime,
EndDate: datetime,
ActivityDisplayName: string,
AdditionalDetails: dynamic
)[
'2025-12-24', '2026-01-04', 'OOO - festive season', dynamic(["Dear colleague, I'm out of office for christmas holiday season and will take care of your request once I'm back.", "In urgent cases, find my mobile number in teams.", "Merry Christmas & looking forward to seeing you soon.", "🎄❄️🎁", "// Nicola"])
# Check Azure AD Access token
if ($null -eq [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens){
Connect-AzureAD
} else {
$token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens
Write-Verbose "Connected to tenant: $($token.AccessToken.TenantId) with user: $($token.AccessToken.UserId)"
}
Connect-AzureAD
$runAsAccountServicePrincipal = Get-AzureADServicePrincipal -ObjectId "497421d0-5b78-4cf1-bab1-6ad2e3d7f319"
$accountAdminDirectoryRole= Get-AzureADDirectoryRole | where-object {$_.DisplayName -eq "User Account Administrator"}
Add-AzureADDirectoryRoleMember -ObjectId $accountAdminDirectoryRole.ObjectId `
-RefObjectId $runAsAccountServicePrincipal.ObjectId
Get-AzureADDirectoryRoleMember -ObjectId $accountAdminDirectoryRole.ObjectId
@nicolonsky
nicolonsky / Test-Guid.ps1
Created May 5, 2020 09:44
Validates a given input string and checks string is a valid GUID
function Test-Guid
{
<#
.SYNOPSIS
Validates a given input string and checks string is a valid GUID
.DESCRIPTION
Validates a given input string and checks string is a valid GUID by using the .NET method Guid.TryParse
.EXAMPLE
Test-Guid -InputObject "3363e9e1-00d8-45a1-9c0c-b93ee03f8c13"
.NOTES
@nicolonsky
nicolonsky / Change-AutopilotOrderID.ps1
Last active February 5, 2024 13:32
Bulk Update Windows Autopilot entities
Connect-MSGraph
Update-MSGraphEnvironment -SchemaVersion "Beta" -Quiet
Connect-MSGraph -Quiet
# Get all autopilot devices (even if more than 1000)
$autopilotDevices = Invoke-MSGraphRequest -HttpMethod GET -Url "deviceManagement/windowsAutopilotDeviceIdentities" | Get-MSGraphAllPages
# Display gridview to show devices
$selectedAutopilotDevices = $autopilotDevices | Out-GridView -OutputMode Multiple -Title "Select Windows Autopilot entities to update"
@nicolonsky
nicolonsky / Detect-M365AppUpdate.ps1
Last active January 30, 2024 12:39
Intune / Configuration Manager Proactive Remediation to trigger Office Click to Run Updater (intended to run for the logged on user to show built-in update pop-up)
# See Microsoft 365 Apps Version history https://learn.microsoft.com/en-us/officeupdates/update-history-microsoft365-apps-by-date#version-history
$targetVersions = @{
'CurrentChannel' = [System.Version]::Parse('16.0.16130.20306')
'MonthlyEnterpriseChannel1' = [System.Version]::Parse('16.0.16026.20238')
'MonthlyEnterpriseChannel2' = [System.Version]::Parse('16.0.15928.20298')
'Semi-AnnualEnterpriseChannel(Preview)' = [System.Version]::Parse('16.0.16130.20306')
'Semi-AnnualEnterpriseChannel1' = [System.Version]::Parse('16.0.15601.20578')
'Semi-AnnualEnterpriseChannel2' = [System.Version]::Parse('16.0.14931.20944')
'CurrentChannel(Preview)' = [System.Version]::Parse('16.0.16227.20094')
@nicolonsky
nicolonsky / SignPowerShell.yaml
Created August 31, 2021 07:41
GitHub actions pipeline to sign PowerShell scripts
name: Sign PowerShell Scripts
on:
push
env:
ARTIFACT_NAME: PowerShell.Workflows.ScriptSigning
jobs:
sign_scripts:
name: Sign and publish PowerShell scripts as pipeline artifacts
@nicolonsky
nicolonsky / Invoke-BinarySearch.ps1
Created November 2, 2020 13:20
Binary Search Algorithm written in PowerShell
#Binary search algorithm with O(logn) complexity written in PowerShell
function Invoke-BinarySearch {
[CmdletBinding()]
[OutputType([int])]
param (
# Array which contains value to search, needs to be sorted
[Parameter(Mandatory)]
[int[]]
$Numbers,
#Requieres -Version 5.0
<#
.SYNOPSIS
You can use this script for troubleshooting or engineering purposes to verify if TCP ports are opened.
.DESCRIPTION
With this Script you are able to specify server names and port numbers to check in a CSV File.
The Script generates an CSV output file as a report.
@nicolonsky
nicolonsky / Restart-WSL.ps1
Created January 2, 2021 14:29
Restart Windows Subsystem for Linux (WSL)
Get-Service LxssManager | Restart-Service