Skip to content

Instantly share code, notes, and snippets.

View steviecoaster's full-sized avatar
🤠
It's a sweet day to write some Powershell

Stephen Valdinger steviecoaster

🤠
It's a sweet day to write some Powershell
View GitHub Profile
@steviecoaster
steviecoaster / Merge-Csv.ps1
Created August 26, 2025 18:10
Quickly merge multiple csv files into a single csv file
function Merge-Csv {
<#
.SYNOPSIS
Merge the data from multiple csv files into one
.DESCRIPTION
Merge data from multiple csv files into one. Data from each file should be the same shape
.PARAMETER CsvFile
The path to two or more csv files to combine
@steviecoaster
steviecoaster / tool.ps1
Created July 2, 2025 17:18
Example NavigationPane app using WinUIShell
using namespace WinUIShell
[CmdletBinding()]
Param()
begin {}
process {
if (-not (Get-Module WinUIShell)) {
Import-Module WinUIShell
}
@steviecoaster
steviecoaster / Test-SqlConnectionString.ps1
Created February 11, 2025 16:51
Test SQL connection strings
function Test-SqlConnectionString {
<#
.SYNOPSIS
Tests establishing a connection to SQL instance usese provided ConnectionString
.DESCRIPTION
Long description
.PARAMETER ConnectionString
The ConnectionString attempting to make a connection
@steviecoaster
steviecoaster / New-UserPrompt.ps1
Created February 10, 2025 20:01
Create a simple user prompt
function New-UserPrompt {
<#
.SYNOPSIS
Generate a simple user prompt
.DESCRIPTION
Long description
.PARAMETER Options
An array of choices a user can select from
@steviecoaster
steviecoaster / exception_class.ps1
Created February 4, 2025 17:24
Create a PowerShell Custom Exception class
class SteviecoasterException : System.Exception { # create a new exception called SteviecoasterException that inherits all of its magic from System.Exception
SteviecoaserException([string]$message) : base($message) {} # message is the text you wish to display as your exception
}
# Use your new class
throw [SteviecoasterException]::new('Welp, I ded')
@steviecoaster
steviecoaster / Convert-GitRemote.ps1
Created January 28, 2025 16:09
Convert the output of 'git remote -v' to a PowerShell object and open one of the remotes in a browser window
function Convert-GitRemote {
<#
.SYNOPSIS
Converts the output of 'git remote -v' to a PowerShell object
.EXAMPLE
Convert-GitRemote
#>
[CmdletBinding()]
@steviecoaster
steviecoaster / switch_scriptblock.ps1
Created January 14, 2025 13:27
Use scriptblocks as evaluation in a PowerShell switch statement
$var = @{A = 10; B = 'abc'}
foreach ($key in $var.Keys) {
switch ($var[$key].GetType()) {
{ $_ -eq [int32] } { "$key + 10 = $($var[$key] + 10)" }
{ $_ -eq [string] } { "$key = $($var[$key])" }
}
}
# Output
@steviecoaster
steviecoaster / sample.ps1
Last active January 10, 2025 21:14
Understanding using Scriptblocks in PowerShell
#Download the sample_script.ps1 contents included in this gist
$url = 'https://gist.githubusercontent.com/steviecoaster/027d2e53b79e200ffb2455f74e2f1308/raw//sample_script.ps1'
$scriptData = [System.Net.WebClient]::new().DownloadString($url)
<#
The above uses the [System.Net.WebClient] .Net class directly, however you can use New-Object if you are more comfortable:
(New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/steviecoaster/027d2e53b79e200ffb2455f74e2f1308/raw/3bc513de7c664915691b6bbd78c49649069f52c5/sample_script.ps1')
#>
# Next, we create our script block, and fill it with our $scriptData
@steviecoaster
steviecoaster / Bootstrap_IIS.ps1
Created January 9, 2025 02:44
Boot strap IIS on windows to host PowerShell Scripts
<#
.SYNOPSIS
Creates the `ChocolateyInstall` IIS fileshare site.
.DESCRIPTION
Creates a new IIS website named `RtpsugDemo` which hosts the
a collection of scripts for onboarding clients to retrieve and run during their
setup.
If you have a need to re-create this for any reason, ensure the existing
@steviecoaster
steviecoaster / Write-ReverseOutput.ps1
Created January 8, 2025 20:40
Fooling around with Write-Output in PowerShell
function Write-ReverseOuput {
[Alias('Write-Output')]
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$InputObject
)
end {