dotfiles/PS/PowerShellProfile.ps1

76 lines
2.1 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> "
}
<#
.Synopsis
Invoke a scriptblock with evelvated permissions.
#>
function Invoke-Elevated {
param (
[ScriptBlock]
$code
)
# Elevate our permissions for this first.
Start-Process powershell.exe -ArgumentList $code -WindowStyle hidden -Verb RunAs
}
<#
.Synopsis
Returns true if you are running with elevated privileges.
#>
function Get-Elevated {
([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
<#
.Synopsis
Create a symlink from a source to a destination.
.Description
Creates a symlink from a $Source to a $Destination.
Automatically elevates to administrator privileges
if necessary.
.Parameter Source
Required source to create the symlink from.
.Parameter Destination
Required destination to create the symlink at.
#>
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
}
}
}
# It's way more useful to call this open than ii
Set-Alias -Name open -Value Invoke-Item
# Add make to our powershell path
$env:PATH="$env:PATH;C:\Program Files (x86)\GnuWin32\bin"