Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Last active August 26, 2025 18:17
Show Gist options
  • Save steviecoaster/bd0bb8681c150279cb23d2e3ca8b2871 to your computer and use it in GitHub Desktop.
Save steviecoaster/bd0bb8681c150279cb23d2e3ca8b2871 to your computer and use it in GitHub Desktop.
My PowerShell Profile script
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
.PARAMETER OutFile
The filename of the combined csv to created
.PARAMETER NoHeader
When used, no header row with column names is provided to the output
.PARAMETER NoClobber
Use this parameter so that Export-Csv does not overwrite an existing file. By default, if the file exists it will be overwritten without warning
.PARAMETER NoTypeInformation
Remove the #TYPE information header from the output. default in PowerShell 6+, included for compatibility
.EXAMPLE
Merge-Csv -CsvFile @('data1.csv', 'data2.csv', 'data3.csv') -OutFile 'combined_data.csv'
Merges three CSV files (data1.csv, data2.csv, and data3.csv) into a single file called combined_data.csv
.EXAMPLE
Merge-Csv -CsvFile @('sales_q1.csv', 'sales_q2.csv') -OutFile 'sales_combined.csv' -NoHeader
Merges two CSV files without including column headers in the output file
.EXAMPLE
Merge-Csv -CsvFile @('report1.csv', 'report2.csv') -OutFile 'final_report.csv' -NoClobber
Merges CSV files but prevents overwriting if final_report.csv already exists
.EXAMPLE
Merge-Csv -CsvFile @('log1.csv', 'log2.csv', 'log3.csv') -OutFile 'all_logs.csv' -NoTypeInformation -NoClobber
Merges three log files, removes PowerShell type information from output, and prevents overwriting existing files
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[ValidateScript({ Test-Path $_ })]
[String[]]
$CsvFile,
[Parameter(Mandatory)]
[String]
$OutFile,
[Parameter()]
[Switch]
$NoHeader,
[Parameter()]
[Switch]
$NoClobber,
[Parameter()]
[Switch]
$NoTypeInformation
)
process {
$csvData = Import-Csv $CsvFile
$csvData | Export-Csv -NoClobber:$NoClobber -NoTypeInformation:$NoTypeInformation -NoHeader:$NoHeader -Path $OutFile
}
}
function Get-OutdatedChocoPackage {
[Alias('outdated')]
[Cmdletbinding()]
Param(
)
choco outdated --limit-output |
ConvertFrom-Csv -Delimiter '|' -Header Id, InstalledVersion, AvailableVersion, Pinned |
Select-Object Id, InstalledVersion, AvailableVersion, @{N = 'Pinned'; E = { [Bool]::Parse($_.Pinned) } } |
Where-Object { [version]$_.AvailableVersion -gt [version]$_.InstalledVersion }
}
function ConvertTo-StarDate {
[CmdletBinding()]
Param(
[Parameter(Mandatory, ValueFromPipeline)]
[DateTime]
$Date
)
end {
# Gregorian bullshit to get # of days in the given year
$cal = [System.Globalization.GregorianCalendar]::new()
$DaysInYear = $cal.GetDaysInYear($Date.Year)
$DayOfYear = $Date.DayOfYear
$step1 = 1000 * ($Date.Year - 2323)
$step2 = ($DayOfYear / $DaysInYear) * 1000
$step3 = $step1 + $step2
[math]::Round($step3, 2)
}
}
function Convert-GitRemote {
[CmdletBinding()]
Param()
end {
$matcher = '^(?<Name>\S+)\s+(?<Url>\S+)\s+\((?<Type>\S+)\)$'
$output = git remote -v
foreach ($line in $output) {
$null = $line -match $matcher
[pscustomobject]@{
Name = $Matches.Name
Url = ($Matches.Url).Trim('.git')
Type = $matches.type
}
}
}
}
function Open-GitRemote {
[Alias('ogr')]
[CmdletBinding()]
Param(
[Parameter()]
[String]
$Name = 'origin',
[Parameter()]
[ValidateSet('fetch', 'push')]
[String]
$Type = 'fetch'
)
end {
$remotes = Convert-GitRemote
$url = ($remotes | Where-Object Type -eq $Type).Url
Start-Process $url
}
}
function Get-Bourbon {
[CmdletBinding()]
Param(
[Parameter()]
[String[]]
$Choice = @('Buffalo Trace', 'Weller', 'Dickle Bonded', 'Envy', 'Statesman', 'Forester Bonded', 'Blantons', 'Bardstown Wheated', 'Bardstown SB', 'Bardstown Rye', 'Sazarac', 'Michters Rye', 'Isaac Bowman', 'Koval')
)
end {
$Choice | Get-Random
}
}
function Open-CertPath {
[Alias('cert')]
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$Domain
)
process {
Invoke-Item (Split-Path -Parent (Get-PACertificate -MainDomain $Domain).PfxFile)
}
}
function New-GitBranch {
[CmdletBinding()]
Param(
[Parameter(Mandatory,Position=0)]
[String]
$Branch,
[Parameter(Mandatory,Position=1)]
[String]
$Trunk
)
process {
switch($Trunk){
'master' {
$commandArgs = [ordered]@{
Fetch = @('fetch','upstream')
Checkout = @('checkout', 'master')
Rebase = @('rebase','upstream/master')
Push = @('push','origin')
Branch = @('checkout','-b',$Branch)
}
}
'main' {
$commandArgs = [ordered]@{
Fetch = @('fetch','upstream')
Checkout = @('checkout', 'main')
Rebase = @('rebase','upstream/main')
Push = @('push','origin')
Branch = @('checkout','-b',$Branch)
}
}
}
$commandArgs.GetEnumerator() | ForEach-Object {
$array = @($_.Value)
& git @array
}
}
}
function Invoke-Lab {
[Alias('lab')]
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory)]
[ValidateSet('start','quit')]
[String]
$Action
)
process {
switch($Action){
'start'{
Start-VagrantEnvironment QSG ; Start-VagrantEnvironment TestEnv
}
'quit' {
Stop-VagrantEnvironment TestEnv ; Stop-VagrantEnvironment QSG
}
}
}
}
function Pop-LELocation {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$Domain
)
process {
Push-Location (Split-Path -Parent (Get-PACertificate -MainDomain $Domain).PfxFile)
}
}
function Start-ChocoBuild {
[cmdletBinding()]
Param(
[Parameter()]
[ValidateSet('Debug','Official')]
[String]
$Type = 'Debug'
)
process {
Write-Verbose "Building from $PWD"
$buildType = Switch ($Type) {
'Debug' { 'build.debug.sh'}
'Official' { 'build.official.sh'}
}
$dockerArgs = @('build','-t','choco:latest-linux', '-f','docker/Dockerfile.linux','.','--build-arg',"buildscript=$buildType")
& docker @dockerArgs
}
}
function Start-ChocoContainer {
[CmdletBinding()]
Param()
process {
Write-Verbose "Running from $PWD"
$dockerArgs = @('run','-ti','--rm','choco:latest-linux','/bin/bash')
docker @dockerArgs
}
}
function Get-DadJoke {
[cmdletBinding()]
Param()
process {
$header = @{
Accept = "application/json"
}
$joke = Invoke-RestMethod -Uri "https://icanhazdadjoke.com/" -Method Get -Headers $header
$joke.joke
}
}
Function prompt {
$fullPath = $ExecutionContext.SessionState.Path.CurrentLocation -split ('/')
"PS | $((Get-Date).ToShortTimeString()) | $($fullpath | select-Object -Last 1)$('>' * ($nestedPromptLevel + 1)) "
}
Function Pop-GH {
[Alias('pgh')]
[cmdletBinding()]
Param(
[Parameter()]
[String]
$Uri = "https://github.com/steviecoaster"
)
start-Process $uri
}
function Update-BoxLink {
[Alias('ubl')]
[cmdletBinding()]
Param(
[Parameter(Mandatory, Position = 0)]
[String]
$Link
)
$NewLink = $($link -replace ("/s/", "/shared/static/")) + ".nupkg"
$NewLink | Set-Clipboard
Write-Host "$NewLink has been placed on your clipboard" -ForegroundColor Blue
}
function ConvertTo-ChocoObject {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline)]
[string]$InputObject
)
Process {
# format of the 'choco list' output is:
# <PACKAGE NAME> <VERSION> (ie. adobereader 2015.6.7)
if (-not [string]::IsNullOrEmpty($InputObject)) {
$props = $_.split('|')
If (-not $audit) {
[pscustomobject]@{
name = $props[0]
version = $props[1]
}
}
Else {
[pscustomobject]@{
name = $props[0]
version = $props[1]
InstalledBy = $props[2] -replace ('User:', '')
Domain = $props[3] -replace ('Domain:', '')
RequestedBy = $props[4] -replace ('Original User:', '')
'InstallDate(UTC)' = $props[5] -replace ('InstallDateUtc:', '')
}
}
}
}
}
Function Open-GitRepo {
<#
.SYNOPSIS
Changes your $pwd to the directory of the requested repo name
.DESCRIPTION
Changes your $pwd to the directory of the requested repo name
.PARAMETER Repo
The repo to open
.EXAMPLE
Open-GitRepo -Repo SuperAwesomeProject
#>
[Alias("Goto")]
[cmdletBinding()]
Param(
[Parameter(Mandatory)]
[ArgumentCompleter(
{
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
$user_profile = if($isMacOS){
$env:HOME
} else {
$env:USERPROFILE
}
$results= Get-ChildItem "$user_profile\Documents\git\ChocoStuff" -Directory | Select-Object -ExpandProperty Name
If ($WordToComplete) {
$results.Where{ $_ -match "^$WordToComplete" }
}
Else {
$results
}
}
)]
[String]
$Repo
)
process {
$user_profile = if($isMacOS){
$env:HOME
} else {
$env:USERPROFILE
}
$path = (Get-ChildItem "$user_profile\Documents\git\ChocoStuff" -Directory | Where-Object { $_.FullName -match "$Repo" }).FullName
Push-Location $path
}
}
function Get-DaysToSummit {
[CmdletBinding()]
Param(
[Parameter()]
[DateTime]
$StartDate
)
$days = (New-TimeSpan -Start (Get-Date) -End $StartDate).Days
Write-Host "Days To Summit: $days!!" -ForegroundColor Blue
}
function Remove-RemoteGitBranch {
[cmdletbinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[String]
$Branch
)
process {
if ($PSCmdlet.ShouldContinue("$Branch","DELETE remote branch")) {
$gitArgs = @('push'
'origin'
'--delete'
$Branch)
git @gitArgs
}
}
}
function Set-CFToken {
[cmdletBinding()]
Param(
[Parameter(Mandatory)]
[SecureString]
$ApiToken
)
process {
$hash = @{
CFToken = $ApiToken
}
return $hash
}
}
function Shock-Employee {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$Name
)
end {
Write-Host "Employee: $Name has been SHOCKED with 220 volts of pure unadulterated pain!!" -ForegroundColor Yellow
}
}
Invoke-Expression (& starship init powershell)
Write-Host "Heads up! Daily dad joke incoming!" -ForegroundColor Green
Write-Host (Get-DadJoke) -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment