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 / dhcplog.ps1
Created July 5, 2023 15:14
DHCP Log Viewer
<#
Event ID Meaning
00 The log was started.
01 The log was stopped.
02 The log was temporarily paused due to low disk space.
10 A new IP address was leased to a client.
11 A lease was renewed by a client.
12 A lease was released by a client.
13 An IP address was found to be in use on the network.
14 A lease request could not be satisfied because the scope's address pool was exhausted.
@scriptingstudio
scriptingstudio / arrayshift.ps1
Last active July 4, 2024 14:03
Concept demo: array shift
<#
$step < 0 - left shift
$step = 0 - reverse
$step > 0 - right shift
#>
function Shift-Array {
[cmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
$Inputobject,
@scriptingstudio
scriptingstudio / ConvertTo-HtmlTable.ps1
Last active May 14, 2024 09:18
Simple and robust PowerShell object to HTML table converter that just works
<#
.SYNOPSIS
Creates HTML table from .NET objects.
.DESCRIPTION
This is basic cmdlet, as a helper, to build HTML tables for complex HTML content.
Converts .NET objects into HTML that can be displayed in a Web browser.
This cmdlet works like "ConvertTo-Html -Fragment" but does not have any of its disadvantages, allowing HTML entities in cells, omiting the first column colons and allowing multi-column tables in the List mode, etc.
Features:
- Parameterset autoresolve. There are no predefined parameter sets
- Input data preprocessor: sorting and filtering
@scriptingstudio
scriptingstudio / Get-WindowsVersion.ps1
Last active November 1, 2024 04:28
Windows version script
function Get-WindowsVersion ([string]$Computername) {
$params = @{}
if ($computername) {
[uint32]$HKLM = 2147483650
$winreg = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$params['CimSession'] = New-CimSession -computername $computername -sessionoption (new-cimsessionoption -protocol Dcom)
if (-not $params['CimSession']) {
$params['CimSession'] = New-CimSession -computername $computername -sessionoption (new-cimsessionoption -protocol wsman)
}
if (-not $params['CimSession']) {return}
@scriptingstudio
scriptingstudio / wt22.ps1
Last active May 27, 2023 12:52
Windows Terminal installation script for Windows Server 2022
param (
[alias('update','install','apply')]
[switch]$run, # action mode
[switch]$force # skips edition limitation
)
If ($PSVersionTable.PSVersion.Major -ge 7) {
Write-Error 'This script needs be run by version of PowerShell prior to 7.0'
}
@scriptingstudio
scriptingstudio / split-distinguishedName.ps1
Last active May 22, 2023 11:57
Extract CN or directory path from DN
# Classic edition v1
function Split-DistinguishedName {
param (
[alias('dn')][string]$distinguishedName,
[alias('leaf')][switch]$cn,
[alias('parent')][switch]$ou,
[switch]$path
)
if (-not $distinguishedName) {return}
$dnpart = $distinguishedName -split '(,DC=)|(,OU=)|(,CN=)',2
@scriptingstudio
scriptingstudio / Align-Object.ps1
Last active March 17, 2025 18:19
Yet another fast way to extend/align objects in the object collection
function Align-Object {
$property = [ordered]@{}
$collection = @($input)
foreach ($obj in $collection) {foreach ($p in $obj.psobject.properties.name) {$property[$p] = 1}}
$collection | Select-Object -property @($property.keys -ne 'Length')
}
function Align-Object1 {
$property = [System.Collections.Generic.HashSet[string]]::new()
$collection = @($input)
foreach ($obj in $collection) {foreach ($p in $obj.psobject.properties.name) {$null = $property.Add($p)}}
@scriptingstudio
scriptingstudio / PSCustomObject.ps1
Last active April 30, 2023 10:17
A simple way to create empty PSCustomObject with properties
[PSCustomObject]@{} | select-object q,w,e,r | gm
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
@scriptingstudio
scriptingstudio / Get-SMARTInfo.ps1
Last active March 20, 2023 06:04
Disk S.M.A.R.T. info
<#
.SYNOPSIS
Reads SMART info from supporting SATA drives.
.PARAMETER CimSession
Specifies an existing CIM session or a computername. By default the script works on local computer.
.PARAMETER NoEmpty
Indicates to exclude drives without SMART information from output.
.EXAMPLE
@scriptingstudio
scriptingstudio / printservicelog.ps1
Last active February 15, 2023 18:52
Windows Print Service Logger
<#
.SYNOPSIS
Print Service Logger.
.DESCRIPTION
The script reads event log ID 307 and ID 805 from the log "Applications and Services Logs > Microsoft > Windows > PrintService" from the specified server and for the specified time period and then calculates print job and total page count data from these event log entries.
It then writes the output to console, graphic window, or .CSV files, one showing by-print job data and the other showing by-user print job data.
Features:
- Predefined date ranges in StartDate parameter