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 / Get-HtmlContent.ps1
Created April 22, 2025 09:36
Simple Webclient wrapper
function Get-HtmlContent {
[CmdletBinding()]
[alias('ghc')]
param (
[Parameter(ValueFromPipeLine, Mandatory)]
[Uri[]]$Uri,
[string]$UserAgent,
[switch]$NoEncoding
)
begin {
@scriptingstudio
scriptingstudio / slicestring.ps1
Last active April 6, 2025 10:30
Regex at work. Strange way to slice strings
function Slice-String ([string]$string, [int]$length, [int[]]$part) {
if ($length -gt 1) {
if ($part.count) {
($string -split "(?<=.)(?=(?:.{$length})+$)")[$part]
} else {
$string -split "(?<=.)(?=(?:.{$length})+$)"
}
} else {$string}
}
@scriptingstudio
scriptingstudio / InvokeTimedCommand.ps1
Last active March 29, 2025 10:35
Yet another way to run timed Powershell commands and scripts
function Invoke-PSCommand {
[CmdletBinding(DefaultParameterSetName='scriptblock')]
[alias('ipsc')]
param (
[Parameter(Mandatory,Position=0,ParameterSetName='scriptblock')]
[ValidateNotNullOrEmpty()]
[alias('sb')][ScriptBlock] $ScriptBlock,
[Parameter(Mandatory,Position=0,ParameterSetName='file')]
[ValidateNotNullOrEmpty()]
[alias('fn')][string] $FileName,
@scriptingstudio
scriptingstudio / get-startitem.ps1
Last active March 22, 2025 14:52
List Start Menu Items in One Line
"C:\ProgramData\Microsoft\Windows\Start Menu\*.lnk",
"$($ENV:APPDATA)\Microsoft\Windows\Start Menu\Programs\*.lnk" |
Get-ChildItem -Recurse | ForEach-Object {
[PSCustomObject]@{
Name = $_.baseName
Shortcut = $_.Fullname
}
} | Sort-Object Name
@scriptingstudio
scriptingstudio / ConvertEventLogRecord.ps1
Last active February 26, 2025 05:21
Yet Another Windows Event Log Record Expander
function Convert-EventLogRecord {
[cmdletbinding()]
[alias('clr','Format-EventLogRecord')]
param (
[Parameter(Position=0,Mandatory,ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[alias('logrecord','events')]
[System.Diagnostics.Eventing.Reader.EventLogRecord[]]$InputObject
)
@scriptingstudio
scriptingstudio / Use-Culture.ps1
Last active March 16, 2025 08:45
Culture-aware command wrapper
function Use-Culture {
param (
[System.Globalization.CultureInfo]$culture = (throw "USAGE: Use-Culture -Culture culture -Script {scriptblock}"),
[ScriptBlock]$script = (throw "USAGE: Use-Culture -Culture culture -Script {scriptblock}")
)
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
trap {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
@scriptingstudio
scriptingstudio / Convert-Object.ps1
Created February 10, 2025 18:25
Array transformation function
<#
Inspired by Doug Finke's map function
https://dfinke.github.io/search%20engines/2024/11/13/Introducing-a-Custom-map-Function-in-PowerShell-for-Functional-Programming.html
#>
function Convert-Object {
[CmdletBinding()]
[alias('map')]
param (
[Parameter(Mandatory)]
$func,
@scriptingstudio
scriptingstudio / nicteam.ps1
Created September 15, 2024 15:11
NIC Team default macaddress setter
<#
.SYNOPSIS
NIC Team default macaddress setter.
.DESCRIPTION
When using DHCP reservation for NIC teaming in Windows Server there is no way of determining which member interface becomes primary at boot. Because it is impossible to determine this, we do not know which member's MAC address will be used by the team. This makes DHCP troublesome.
#>
param (
[alias('name')][string]$teamname,
[string]$macaddress,
[alias('apply')][switch]$run
@scriptingstudio
scriptingstudio / rmvmware.ps1
Last active February 17, 2025 10:51
Yet Another VMware Tools Remover
<#
.SYNOPSIS
VMware Tools Remover
.DESCRIPTION
This script will automatically rip out all VMware Tools registry entries,
files, drivers, DLLs, and services for Windows 7-11, 2008-2022.
Features:
- View/Action modes
@scriptingstudio
scriptingstudio / compress-range.ps1
Last active January 25, 2025 21:26
Simple numerical series compressor
function compress-range ([int[]]$inputobject, [switch]$sort, [switch]$unique) {
if (-not $inputobject.count) {return}
$first = $true
$range = $inputobject[0],$inputobject[0]
$param = @{}
if ($unique) {$param['unique'] = $true}
$sb = if ($sort) {{$inputobject | Sort-Object @param}} else {{$inputobject}}
foreach ($e in (.$sb)) {
$diff = [math]::Abs($e - $range[1])
if ($diff -eq 1) {$range[1]++}