Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aldrichtr/8c38196d48d00c5ee727ed9f7a7681d3 to your computer and use it in GitHub Desktop.
Save aldrichtr/8c38196d48d00c5ee727ed9f7a7681d3 to your computer and use it in GitHub Desktop.
My PowerShell Profile Basics
#Simple functions and aliases that don't rise to the level of a module that I like having in my PowerShell Profile
function sudo {[CmdletBinding(<#PositionalBinding=$True#>)]PARAM([String]$CommandLine,[Switch]$RunPrior) IF($RunPrior.IsPresent) {$CommandLine = (Get-History | Select-Object -Last 1).CommandLine}; Write-Verbose "Running: $CommandLine"; start-process powershell -verb:Runas "$CommandLine"}
function outlook {. 'C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE' /restore}
function newdir {PARAM($Path) new-item -ItemType Directory -Path $Path }
function ssms2008 {ls 'C:\Program Files\', 'C:\Program Files (x86)\' -Filter micro*Sql*server | ls -Filter '100' | ls -Recurse -Filter *ssms*exe | ii}
new-alias psedit -Value "$env:windir\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe" -Force
function Get-HistoryWhere {Param([Parameter(Mandatory=$false,Position = 0)][String]$Contains,[Parameter(Mandatory=$false,Position = 1)][Int]$Last) $hist = Get-History; If ($PSBoundParameters.ContainsKey('Last') ) { $hist = $hist | Select-Object -Last $Last } ; If ($PSBoundParameters.ContainsKey('Contains')) {$hist = $hist | where {$_.CommandLine -like "*$Contains*"} }; return $hist}
function pesterfoo { powershell -noprofile {get-module -listavailable "Microsoft.Powershell*","CimCmdlets" | import-module; $PSModuleAutoloadingPreference = "none"; import-module Pester; invoke-pester (ls *tests.ps1 ) ; git status; git log -n 1 --oneline --decorate; git diff --stat}<#End Powershell#> }<#END pesterfoo#>
function dise {displayswitch.exe /external}
new-alias import -Value 'import-module'
function newfile {PARAM( [Parameter(Mandatory=$true,Position=0)]$Name,[Parameter(Mandatory=$false,Position=1)]$Value='') new-item -ItemType File -Path . -Name $Name -Value $Value}
function gitmit {Param() begin{} process {$out = ''; foreach ($i in $args) {$out += "$i "}; git commit -m $out } end{}}
function Rename-PSWindow {$host.ui.RawUI.WindowTitle = $($args -join ' ')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment