Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Last active December 8, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsmelton/baff726a43567bed746ff241b7b40f7b to your computer and use it in GitHub Desktop.
Save wsmelton/baff726a43567bed746ff241b7b40f7b to your computer and use it in GitHub Desktop.
#$PSDefaultParameterValues = @{ "*:Credential" = (Get-Secret username) }
if ($psedition -ne 'Core') {
[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12", "Tls11", "Tls", "Ssl3")
}
function Prompt {
$major = $PSVersionTable.PSVersion.Major
$minor = $PSVersionTable.PSVersion.Minor
$patch = $PSVersionTable.PSVersion.Patch
if ($major -lt 6) {
Write-Host "[PS $($major).$($minor)] [" -NoNewline
} else {
$patch = $PSVersionTable.PSVersion.Patch
Write-Host "[PS $($major).$($minor).$($patch)] [" -NoNewline
}
Write-Host (Get-Date -Format "HH:mm:ss") -ForegroundColor Gray -NoNewline
try {
$history = Get-History -ErrorAction Ignore -Count 1
if ($history) {
Write-Host "] " -NoNewline
$ts = New-TimeSpan $history.StartExecutionTime $history.EndExecutionTime
switch ($ts) {
{ $_.TotalMinutes -ge 1 } {
'[{0,5:f1} m ]' -f $_.TotalMinutes | Write-Host -ForegroundColor DarkRed -NoNewline
}
{ $_.TotalMinutes -lt 1 -and $_.TotalSeconds -ge 1 } {
'[{0,5:f1} s ]' -f $_.TotalSeconds | Write-Host -ForegroundColor DarkYellow -NoNewline
}
default {
'[{0,5:f1}ms ]' -f $_.Milliseconds | Write-Host -ForegroundColor Cyan -NoNewline
}
}
} else {
Write-Host "] >" -ForegroundColor Gray -NoNewline
}
} catch { }
if (Test-Path .git) {
$branchName = git branch | ForEach-Object { if ( $_ -match "^\*(.*)" ) { $_ -replace "\* ", "" } }
Write-Host "[ git:$branchName ]" -ForegroundColor Yellow -NoNewline
}
Write-Host " $($executionContext.SessionState.Path.CurrentLocation.ProviderPath)"
"[$($MyInvocation.HistoryId)] > "
}
function rdp {
[cmdletbinding()]
param (
$server,
$username = 'username', #defaults to saved Secret for admin account
[switch]$fullScreen
)
$secret = Get-Secret $username
try {
cmdkey /generic:"$server" /user:"$($secret.username)" /pass: "$($secret.GetNetworkCredential().Password)" >$null
} catch {
throw "unable to save cmdkey secret: $_"
}
if ($fullScreen) {
mstsc.exe -v $server -f
} else {
mstsc.exe -v $server /w 2150 /h 1250
}
}
function findshit ($str,$path) {
$str = [regex]::escape($str)
Select-String -Pattern $str -Path (Get-ChildItem $path -Recurse -Exclude 'allcommands.ps1', '*.dll', "*psproj")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment