dotfiles/PS/PowerShellProfile.ps1

50 lines
1.5 KiB
PowerShell

# My powershell profile.
# customize the prompt to be a little more useful
function prompt {
Write-Host -NoNewLine "["
Write-Host -NoNewLine -Fore Green ("{0:HH}:{0:mm}" -f $(get-date))
Write-Host -NoNewLine "] "
Write-Host -Fore Cyan "${pwd}"
"PS> "
}
function Invoke-Elevated {
param (
[ScriptBlock]
$code
)
# Elevate our permissions for this first.
Start-Process powershell.exe -ArgumentList $code -WindowStyle hidden -Verb RunAs
}
# helper command to get whether we are running under elevated privileges or not.
function Get-Elevated {
([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Helper command to make symbolic links.
function New-Link {
param (
[Parameter(Position=0, Mandatory=$true)]
[String[]]
$Source,
[Parameter(Position=1, Mandatory=$true)]
[String[]]
$Destination
)
# This is a bit of a hack but it's necessary until they make it possible
# to do symbolic links without administrator privileges
if (Get-Elevated) {
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
} else {
# Elevate our permissions for this first.
Invoke-Elevated {
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
}
}
}