160 lines
5.6 KiB
PowerShell
160 lines
5.6 KiB
PowerShell
# Put this in the location of $PROFILE. For PowerShell 5+ this is either
|
|
# C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
|
|
# or
|
|
# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
|
|
|
|
function Prompt {
|
|
if ($IsWindows -or ($env:OS -eq "Windows_NT")) {
|
|
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
|
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
return "# "
|
|
}
|
|
}
|
|
return "> "
|
|
}
|
|
|
|
function ADUserInfo {
|
|
param (
|
|
[Parameter(Mandatory)]
|
|
[string]$User
|
|
)
|
|
Import-Module ActiveDirectory -ErrorAction Stop
|
|
$ADPropertiesCommon = @(
|
|
'SamAccountName'
|
|
'UserPrincipalName'
|
|
'DisplayName'
|
|
'Enabled'
|
|
'PasswordExpired'
|
|
'LockedOut'
|
|
'CannotChangePassword'
|
|
'PasswordNeverExpires'
|
|
'GivenName'
|
|
'Surname'
|
|
'DistinguishedName'
|
|
'EmployeeID'
|
|
'Title'
|
|
'Department'
|
|
'Created'
|
|
'Modified'
|
|
'PasswordLastSet'
|
|
)
|
|
$ADPropertiesGetOnly = @(
|
|
'msDS-UserPasswordExpiryTimeComputed'
|
|
)
|
|
$ADPropertiesPrintOnly = @(
|
|
@{Name = "PasswordExpiresDate"; Expression = { [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed") } }
|
|
)
|
|
$ADPropertiesGet = $ADPropertiesCommon + $ADPropertiesGetOnly
|
|
$ADPropertiesPrint = $ADPropertiesCommon + $ADPropertiesPrintOnly
|
|
Get-ADUser -Properties $ADPropertiesGet -Identity $User | Select-Object -Property $ADPropertiesPrint
|
|
}
|
|
|
|
function mkcd {
|
|
param (
|
|
[Parameter(Mandatory)]
|
|
[string]$Path
|
|
)
|
|
New-Item -ItemType Directory -Path $Path
|
|
Set-Location -Path $Path
|
|
}
|
|
|
|
function Set-AcpLocale {
|
|
# Set the default en-GB locale.
|
|
Set-WinUserLanguageList -LanguageList en-GB -Force
|
|
# Get the default locale back.
|
|
$AcpLocale = Get-WinUserLanguageList
|
|
# Remove the British layout and add the US layout.
|
|
$AcpLocale[0].InputMethodTips.Remove("0809:00000809") | Out-Null
|
|
$AcpLocale[0].InputMethodTips.Add("0809:00000409") | Out-Null
|
|
# Set the locale to our customised version.
|
|
Set-WinUserLanguageList -LanguageList $AcpLocale -Force
|
|
# Clean up.
|
|
Remove-Variable AcpLocale
|
|
}
|
|
|
|
if ($IsWindows -or ($env:OS -eq "Windows_NT")) {
|
|
function who {
|
|
& "$env:SystemRoot\System32\query.exe" user
|
|
}
|
|
|
|
# Drop elevation privileges.
|
|
$env:__COMPAT_LAYER = "RunAsInvoker"
|
|
}
|
|
|
|
if ($nvim = Get-Command nvim.exe -ErrorAction SilentlyContinue) {
|
|
Set-Alias -Name vi -Value $nvim.Source
|
|
}
|
|
Remove-Variable -Name nvim
|
|
|
|
# Force UTF-8 output.
|
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
Set-PSReadLineOption -BellStyle None
|
|
Set-PSReadLineOption -EditMode Emacs
|
|
Set-PSReadLineOption -HistorySaveStyle SaveNothing
|
|
|
|
Remove-PSReadLineKeyHandler -Chord Tab
|
|
Set-PSReadLineKeyHandler -Chord UpArrow -ScriptBlock {
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward()
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
|
|
}
|
|
Set-PSReadLineKeyHandler -Chord DownArrow -ScriptBlock {
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward()
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
|
|
}
|
|
Set-PSReadLineKeyHandler -Chord Ctrl+LeftArrow -Function BackwardWord
|
|
Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord
|
|
Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord
|
|
Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord
|
|
Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function SelfInsert
|
|
|
|
# Set terminal to light mode.
|
|
foreach ($Property in $Host.PrivateData.PSObject.Properties.Name) {
|
|
if ($Property -match '.*ForegroundColor$') {
|
|
$Host.PrivateData.$Property = $Host.UI.RawUI.ForegroundColor
|
|
}
|
|
if ($Property -match '.*BackgroundColor$') {
|
|
$Host.PrivateData.$Property = $Host.UI.RawUI.BackgroundColor
|
|
}
|
|
}
|
|
|
|
[bool]$LightMode = $true
|
|
if ($LightMode) {
|
|
$Host.PrivateData.ErrorForegroundColor = [ConsoleColor]::DarkRed
|
|
$Host.PrivateData.ErrorBackgroundColor = [ConsoleColor]::White
|
|
$Host.PrivateData.WarningForegroundColor = [ConsoleColor]::DarkYellow
|
|
$Host.PrivateData.WarningBackgroundColor = [ConsoleColor]::White
|
|
$Host.PrivateData.DebugForegroundColor = [ConsoleColor]::DarkYellow
|
|
$Host.PrivateData.DebugBackgroundColor = [ConsoleColor]::White
|
|
$Host.PrivateData.VerboseForegroundColor = [ConsoleColor]::DarkYellow
|
|
$Host.PrivateData.VerboseBackgroundColor = [ConsoleColor]::White
|
|
$Host.PrivateData.ProgressForegroundColor = [ConsoleColor]::DarkYellow
|
|
$Host.PrivateData.ProgressBackgroundColor = [ConsoleColor]::White
|
|
$PSReadLineLightColors = @{
|
|
Default = "$([char]0x1b)[0m"
|
|
Command = "$([char]0x1b)[0m"
|
|
Comment = "$([char]0x1b)[32m"
|
|
ContinuationPrompt = "$([char]0x1b)[0m"
|
|
Emphasis = "$([char]0x1b)[36m"
|
|
Error = "$([char]0x1b)[91m"
|
|
InlinePrediction = "$([char]0x1b)[95m"
|
|
Keyword = "$([char]0x1b)[32m"
|
|
ListPrediction = "$([char]0x1b)[47;90m"
|
|
ListPredictionSelected = "$([char]0x1b)[100;97m"
|
|
ListPredictionTooltip = "$([char]0x1b)[45;33m"
|
|
Member = "$([char]0x1b)[0m"
|
|
Number = "$([char]0x1b)[31m"
|
|
Operator = "$([char]0x1b)[90m"
|
|
Parameter = "$([char]0x1b)[90m"
|
|
Selection = "$([char]0x1b)[7m"
|
|
String = "$([char]0x1b)[36m"
|
|
Type = "$([char]0x1b)[0m"
|
|
Variable = "$([char]0x1b)[32m"
|
|
}
|
|
Set-PSReadLineOption -Colors $PSReadLineLightColors
|
|
}
|
|
|
|
# Keep this at the end.
|
|
if (Test-Path "$PSScriptRoot/local.ps1") {
|
|
. "$PSScriptRoot/local.ps1"
|
|
}
|