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 / readpdf.ps1
Last active February 23, 2024 05:56
Simple PDF Reader
# https://www.nuget.org/packages/itextsharp/ (5.5.13.3)
# https://github.com/itext/itextsharp/releases/tag/5.5.13
Add-Type -Path "$psscriptroot\itextsharp.dll" # 5.5.13 and lower have no dependencies
function Read-Pdf {
[CmdLetBinding(DefaultParameterSetName="Path")]
param (
[Parameter(ParameterSetName="Path", Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position=0)]
[alias('fullname')][string[]]$path,
[Parameter(ParameterSetName="Instance", Position=0)]
@scriptingstudio
scriptingstudio / Join-String.ps1
Last active February 28, 2024 02:54
A missing Windows PowerShell function.
function Join-String {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]$Inputobject,
[string]$Property, [string]$Separator='',
[string]$OutputPrefix, [string]$OutputSuffix,
[switch]$SingleQuote, [switch]$DouleQuote,
[string]$FormatString
)
begin {
@scriptingstudio
scriptingstudio / ExcelQuery.ps1
Last active August 27, 2023 18:32
A simple way to get Excel content without Excel installed
<#
.SYNOPSIS
Reads data from Excel file into PowerShell object.
.DESCRIPTION
Uses OLEDB provider to execute a SQL statement against a XLSX file to read data. This cmdlet assumes a file path will be passed in and treating all results as text.
Features:
* Can read entire workbook
* Can get workbook sheet names
* Parameterized query
@scriptingstudio
scriptingstudio / psquser.ps1
Last active August 1, 2023 10:54
quser.exe PowerShell wrapper
function PSQUser {
param (
[alias('inputobject','server','srv','ipaddress')]
[string[]]$computerName = 'localhost'
)
$quserPattern = @(
'(?<UserName>>?\S+)'
'(?<SessionName>(\w+)?)'
'(?<Id>\d+)'
@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 May 28, 2023 14:10
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