You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB
PowerShell

#region keybindings
Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadlineKeyHandler -Key Ctrl+d -Function ViExit
#endregion keybindings
#region prompt dependencies
#set part of the prompt beforehand to optimize the prompt function
#depending on elevated permissions change the delimiter
$identity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if($identity.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$delimiter = '#'
} else {
$delimiter = '$'
}
$username = $env:USERNAME.ToLower()
$computername = $env:COMPUTERNAME.ToLower()
#endregion prompt dependencies
function prompt {
#shorten path with tilde if possible
#uses .Replace() to prevent regex
$cwd = (Get-Location).Path.Replace($HOME,'~')
'[{0}@{1} {2}]{3} ' -f $username,$computername,$cwd,$delimiter
}
function Get-BetterADUser {
param (
[Parameter(Mandatory=$true,
Position=0)]
[string]
$SearchTerm,
[string]
$Server = $env:USERDNSDOMAIN
)
$filter = 'UserPrincipalName -like "*{0}*" -or Name -like "*{0}*"' -f $SearchTerm
Get-ADUser -Filter $filter -Server $Server
}
function Get-Feierabend {
param (
[Parameter(Position = 0)]
[datetime]
$Begin,
[Parameter(Position = 1)]
[datetime]
$PauseStart,
[Parameter(Position = 2)]
[datetime]
$PauseEnd,
[Parameter(Position = 3)]
[single]
$Hours = 6.5
)
$Begin.AddHours($Hours).Add($PauseEnd - $PauseStart)
}
function fsh {
param (
[string]$ComputerName
)
$host.UI.RawUI.WindowTitle = $ComputerName
Enter-PSSession @PSBoundParameters @args
}
#check for old version
if($PSVersionTable.PSVersion.Major -le 5){
Write-Host -ForegroundColor Red 'start pwsh instead of powershell'
}