Skip to content

Instantly share code, notes, and snippets.

@eodomo
Created January 9, 2025 19:45
Show Gist options
  • Save eodomo/ec685d9d7a57f538905b2ca06544e627 to your computer and use it in GitHub Desktop.
Save eodomo/ec685d9d7a57f538905b2ca06544e627 to your computer and use it in GitHub Desktop.
PowerShell Profile
# Place this file at C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1 to apply to all users on current computer
# Alt path: $PSPATH\Microsoft.PowerShell_profile.ps1
function Prompt {
$path = $executionContext.SessionState.Path.CurrentLocation.Path
$p = $path
while ($p -ne "") {
if($p -eq $HOME) { $path = $path.Replace($HOME,"~"); break}
$p = Split-Path $p
}
"PS $path$('>' * ($nestedPromptLevel + 1)) ";
}
function GoTo-TicketFolder{
param (
[Parameter(Mandatory=$true)]
[string]$ClientName,
[Parameter(Mandatory=$true)]
[string]$TicketNumber,
[bool]$CmdOnly = $false,
[System.IO.FileInfo]$SearchFolder = "~\Documents"
)
$ClientPath = Join-Path $SearchFolder $ClientName
if (!(Test-Path $ClientPath)) {
$response = Read-Host "Client Does not have a folder, would you like to make one? (y/n)"
if ($response -match "(y|yes)") {
$ClientPath = New-Item -Type Directory -Path $ClientPath
} else {
$ClientFolderList = Get-ChildItem -Directory $SearchFolder -Name
Write-Host "These are the client folders that currently exist:"
$ClientFolderList
return
}
}
$TicketFolders = Get-ChildItem $ClientPath | ? {$_.name -like "$TicketNumber*"}
if (!($TicketFolders)) {
$response = Read-Host "Ticket folder does not exist, would you like to make one? (y/n)"
if ($response -match "(y|yes)") {
$TicketSummary = Read-Host "Ticket title"
$invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
$TicketSummary = -join ($TicketSummary.ToCharArray() | ? {$invalidChars -NotContains $_ })
$FolderName = "$TicketNumber - $TicketSummary"
$TicketFolder = Join-Path $ClientPath $FolderName
$TicketFolder = New-Item -Type Directory -Path $TicketFolder
$TicketFolders = $TicketFolder
}
}
foreach ($TicketFolder in $TicketFolders) {
if (!($CmdOnly)) {
explorer $TicketFolder
}
cd $TicketFolder
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment