Skip to content

Instantly share code, notes, and snippets.

@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 / Restart-WSL.ps1
Created January 2, 2021 14:29
Restart Windows Subsystem for Linux (WSL)
Get-Service LxssManager | Restart-Service
@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,
@nicolonsky
nicolonsky / Remediate-DefenderQuickScan.ps1
Created September 28, 2020 21:03
Endpoint analytics, Proactive remediations start Defender quick scan
Start-MpScan -ScanType QuickScan
@nicolonsky
nicolonsky / Detect-DefenderQuickScanRequired.ps1
Created September 28, 2020 21:02
Endpoint analytics detection script for recent Defender quick scan
# Configure remediation threshold, e.g. 1 day
# Diduct this value from current datetime
$thresholdDateTime = (Get-Date).AddDays(-1)
# Get defender eventlog entries which indicate successful scan
$mostRecentScan = Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | Where-Object { $_.ID -in @(1001) } | Select-Object -First 1
if ($mostRecentScan.TimeCreated -lt $thresholdDateTime) {
Write-Warning "No Microsoft Defender Antivirus scan has been completed sine `"$thresholdDateTime`""
Exit 1
@nicolonsky
nicolonsky / Create-ClientCredentialCertificate.ps1
Last active May 10, 2020 21:03
Create Azure AD App Registration Client Credential Certificate
$displayName = "Microsoft Graph PowerShell Client Credentials"
$notAfter = $(Get-Date).AddYears(1)
$cert = New-SelfSignedCertificate -CertStoreLocation cert:\currentuser\my -DnsName graph.microsoft.com -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $notAfter -FriendlyName $displayName
$export = Export-Certificate -Cert "cert:\currentuser\my\$($cert.Thumbprint)" -FilePath "c:\temp\$displayName.cer"
Write-Output "Exported certificate '$($cert.Thumbprint)' to '$($export.FullName)'"
@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
# 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)"
}
@nicolonsky
nicolonsky / DisableSelfServicing.ps1
Created March 11, 2020 09:31
Disable self-service purchases
# Disable Office 365 Self-Servicing Purchases
# src: https://docs.microsoft.com/en-us/microsoft-365/commerce/subscriptions/allowselfservicepurchase-powershell?view=o365-worldwide
# Install abd connect MSCommerce services with PowerShell
Install-Module -Name MSCommerce -Scope CurrentUser
Connect-MSCommerce
Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase
# Disable Self-Servicing for all products