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 / fibonacci.ps1
Last active January 30, 2023 15:22
Powershell fibonacci - just for fun
# DEMO: caching calculations demo - superfast
# reverse calculations
function fibonacciR ([Double]$fn, [switch]$series, $fbcache) {
#if ($MyInvocation.MyCommand.name -ne $(Get-PSCallStack)[1].FunctionName) {
# $fbcache = $null # prevent using $fbcache from root
#}
if ($fbcache -eq $null) {$fbcache = [System.Collections.Generic.Dictionary[string,Double]]::new($fn)}
if ($fbcache.ContainsKey($fn)) {$fbcache[$fn]}
elseif ($fn -lt 2) {
$fbcache[$fn] = $fn
@scriptingstudio
scriptingstudio / safedate.ps1
Last active January 6, 2023 18:58
Safe date format
# safe (culture invariant) date format - ISO 8601 - YYYY-MM-DD
[datetime]::now.tostring('yyyy-MM-dd')
@scriptingstudio
scriptingstudio / Foreach-Parallel.ps1
Last active January 14, 2023 06:33
Foreach-Parallel
<#
.SYNOPSIS
Performs parallel processing of input objects.
.DESCRIPTION
Simple PowerShell function to asynchronously run jobs.
Yet another parallel processing manager on Earth.
FEATURES:
- no modules, just one small self-sufficient function
- automatic scriptblock variables: $_, $psitem
@scriptingstudio
scriptingstudio / gporeport.ps1
Last active January 29, 2023 07:51
Quick GPO Report
# Quick GPO Report for further analysis
param (
[string]$csv,
[alias('xlsx')][string]$excel
)
$gporeport = {
$domain = $env:USERDNSDOMAIN
if (-not $domain) {return}
#$dommask = "$domain/" -replace '\.','\.'
@scriptingstudio
scriptingstudio / asyncprogressbar.ps1
Created February 9, 2023 15:52
Simple one-level asynchronous wrapper over the builtin PowerShell progress bar
<#
.SYNOPSIS
Displays an asynchronous progress bar within a PowerShell command window.
.DESCRIPTION
A simple one-level asynchronous wrapper over the builtin PowerShell progress bar.
Features:
- Non-blocking screen output
- Separate run phases: start,next,stop
- Automatic percentage calculation
- Automatic state control
@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
@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 / 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 / Align-Object.ps1
Last active July 30, 2023 14:35
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')
}
[pscustomobject] @{ one = 1; two = 2; three = 3 },
[pscustomobject] @{ six = 133; seven = 2; three = 3 },
[pscustomobject] @{ one = 10; three = 30; four = 4 } |
@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