Skip to content

Instantly share code, notes, and snippets.

View SvenAelterman's full-sized avatar

Sven Aelterman SvenAelterman

View GitHub Profile
@SvenAelterman
SvenAelterman / WVDConnections_byUser_byClientVersion,kql
Created April 27, 2023 13:33
Query Azure Virtual Desktop (AVD) connection logs for client versions used by users over time
View WVDConnections_byUser_byClientVersion,kql
let startTime = ago(30d);
WVDConnections
| where TimeGenerated > startTime
| summarize min(TimeGenerated), max(TimeGenerated) by UserName, ClientOS, ClientType, ClientVersion
| sort by UserName, min_TimeGenerated
View ohmyposh-svaelter.omp.json
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#0077c2",
"foreground": "#ffffff",
"leading_diamond": "",
@SvenAelterman
SvenAelterman / Uninstall-OutdatedChildModules.ps1
Created October 17, 2022 13:29
Uninstall-OutdatedChildModules.ps1
View Uninstall-OutdatedChildModules.ps1
[CmdletBinding(SupportsShouldProcess = $True)]
Param(
[Parameter(Mandatory, Position = 1)]
[string]$ModuleName
)
$Latest = Get-InstalledModule $ModuleName -ErrorAction Ignore;
# If this module is installed at all
if ($Latest) {
@SvenAelterman
SvenAelterman / Remove-UnattachedNIC.ps1
Last active May 12, 2022 02:28
Remove-Unattached-NICs
View Remove-UnattachedNIC.ps1
$deleteUnattachedNICs = $false
# List all unattached NICs
$unattachedNICs = Get-AzNetworkInterface | `
Where-Object { $_.VirtualMachine -eq $null -and ($_.PrivateEndpointText -eq $null -or $_.PrivateEndpointText -eq 'null') }
# Iterate over the unattached NICs
foreach ($nic in $unattachedNICs) {
# Find a lock for the NIC (or resource group/subscription/...)
$lock = Get-AzResourceLock -ResourceName $nic.Name -ResourceGroupName $nic.ResourceGroupName -ResourceType 'Microsoft.Network/networkInterfaces'
@SvenAelterman
SvenAelterman / Remove-OutdatedPSModules.ps1
Created December 17, 2021 01:10
Finds and removes PowerShell modules for which newer versions are already installed.
View Remove-OutdatedPSModules.ps1
# Adapted from http://sharepointjack.com/2017/powershell-script-to-remove-duplicate-old-modules/
Write-Host "This will remove all old versions of installed modules."
Write-Host "Be sure to run this as an admin if modules are installed machine-wide." -ForegroundColor Yellow
Write-Host "(You can update all your Az modules with 'Update-Module Az -Force')."
# This will retrieve all the latest versions of installed modules
$mods = Get-InstalledModule
# Loop through all installed modules
foreach ($Mod in $mods) {
@SvenAelterman
SvenAelterman / New-ApiPermissionForManagedIdentity.ps1
Last active October 28, 2021 14:31
Adding (Microsoft Graph) API permissions to a Managed Identity (such as for Logic Apps).
View New-ApiPermissionForManagedIdentity.ps1
# From https://aztoso.com/security/microsoft-graph-permissions-managed-identity/
# Your tenant id (in Azure Portal, under Azure Active Directory -> Overview )
$TenantID = ""
# Microsoft Graph App ID (DON'T CHANGE)
$GraphAppId = "00000003-0000-0000-c000-000000000000"
# Name of the system managed identity (same as the Logic App name)
$DisplayNameOfMSI = "demoLogicApp"
# Check the Microsoft Graph documentation for the permission you need for the operation
$PermissionName = "Domain.Read.All"
@SvenAelterman
SvenAelterman / Get-WindowsSearchIndexResults.ps1
Last active October 31, 2021 20:27
PowerShell to query local Windows Search index (e.g., for Visio shapes)
View Get-WindowsSearchIndexResults.ps1
$contents = "Virtual"
$sql = "SELECT System.ItemName, System.ItemUrl FROM SYSTEMINDEX WHERE Contains(*,'$($contents)') AND System.ItemType='.VSSX'"
$Provider = "Provider=Search.CollatorDSO;Extended Properties=’Application=Windows’;"
$adapter = new-object system.data.oledb.oleDBDataadapter -argument $sql, $Provider
$ds = new-object system.data.dataset
if ($adapter.Fill($ds)) { $ds.Tables[0] }
@SvenAelterman
SvenAelterman / CEF_generator.py
Created September 16, 2021 02:12
CEF generator in Python
View CEF_generator.py
#!/usr/bin/python3
# Simple Python script designed to write to the local Syslog file in CEF format on an Azure Ubuntu 18.04 VM.
# Frank Cardinale, April 2020
# Sven Aelterman, September 2021
# Importing the libraries used in the script
import random
import syslog
import time
@SvenAelterman
SvenAelterman / Set-ClusterProbePort
Created June 30, 2021 22:26
Sets the cluster probe port for Windows Server Failover Cluster (WSFC) in Azure using a load balancer (traditional VNN, not needed for DNN). This is an enhancement to the script at https://docs.microsoft.com/en-us/azure/azure-sql/virtual-machines/windows/availability-group-listener-powershell-configure#configure-the-listener
View Set-ClusterProbePort
Import-Module FailoverClusters
[int]$ClusterProbePort = 58888 # The probe port from the WSFCEndPointprobe in the Azure portal. This port must be different from the probe port for the availability group listener probe port.
# Retrieve info from the cluster
$ClusterNetworkName = (Get-ClusterNetwork).Name
$IPResource = (Get-ClusterResource | Where {($_.OwnerGroup -eq "Cluster Group" -And $_.ResourceType -eq "IP Address")})
$IPResourceName = $IPResource.Name
$ClusterCoreIP = ($IPResource | Get-ClusterParameter | Where { $_.Name -eq "Address" }).Value
View Azure-CopyManagedDisks.ps1
<#
Written with version 2.8.0 of the Azure PowerShell Module
available from here https://github.com/Azure/azure-powershell/releases/tag/v2.8.0-October2019
or run: Install-Module -Name Az -RequiredVersion 2.6.0 -AllowClobber
Migration instructions Azure.RM to Az - https://azure.microsoft.com/en-au/blog/how-to-migrate-from-azurerm-to-az-in-azure-powershell/
#>
# from https://poshtools.com/2018/04/10/cross-platform-out-gridview-using-universal-dashboard/
function Out-GridView
{