Skip to content

Instantly share code, notes, and snippets.

View scriptingstudio's full-sized avatar
👍
Awake and ready

Matthew Gray scriptingstudio

👍
Awake and ready
  • Interstellar Systems
  • Hiranyaloka
View GitHub Profile
@scriptingstudio
scriptingstudio / xml2string.ps1
Created May 16, 2025 03:00
XML to string converter
function Convert-XmlToString {
param (
[Parameter(Mandatory,ValueFromPipeline)]
$xml
)
begin {
$sw = [System.IO.StringWriter]::new()
$xmlSettings = [System.Xml.XmlWriterSettings]::new()
$xmlSettings.ConformanceLevel = [System.Xml.ConformanceLevel]::Fragment
$xmlSettings.Indent = $true
@scriptingstudio
scriptingstudio / testleap.ps1
Last active May 18, 2025 09:11
Test leap year in one line
# But [datetime]::IsLeapYear is faster anyway
function Test-IsLeap ([uint32]$year) {
(($year * 1073750999) -band 3221352463) -le 126976
}
@scriptingstudio
scriptingstudio / testadmin.cmd
Created May 22, 2025 07:16
Culture invariant admin privileges test in cmd
powershell.exe -executionpolicy bypass -noninteractive -nologo -noprofile -command "&{ If (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {write-warning 'You must run this script as an Administrator!'; cmd.exe /c pause; exit 1000} }"
if ERRORLEVEL 1000 goto :EOF
@scriptingstudio
scriptingstudio / getremaining.ps1
Last active June 3, 2025 02:31
Get ValueFromRemainingArguments/Args as HashTable
function test-remaining {
[cmdletbinding()]
param (
[parameter(ValueFromRemainingArguments)]
$remaining
)
$htRemaining = [ordered]@{}
$unnamed = [System.Collections.Generic.list[object]]::new()
$remaining | ForEach-Object {
@scriptingstudio
scriptingstudio / fixmac.ps1
Last active July 11, 2025 15:10
Work around for a faulty network adapter
#Requires -RunAsAdministrator
<#
There are weird computers having physical netadapters without macaddress.
This script finds faulty netadapters and assigns a random macaddress to the adapter
#>
Get-NetAdapter -Physical -ErrorAction 0 | Where-Object {
$_.InterfaceDescription -notmatch 'Wireless|wi-fi|virt|Hyper-V' -and $_.MacAddress -eq '00-00-00-00-00-00'
} | ForEach-Object {