2022-01-18 11:48:49 +00:00
|
|
|
# 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 {
|
2023-03-19 22:38:03 +00:00
|
|
|
if ($IsWindows -or ($env:OS -eq "Windows_NT")) {
|
2022-03-02 11:56:41 +00:00
|
|
|
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
|
|
|
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
2023-09-15 10:37:12 +00:00
|
|
|
return "${env:USERNAME}@$(${env:COMPUTERNAME}.ToLower())# "
|
2022-03-02 11:56:41 +00:00
|
|
|
} else {
|
2023-09-15 10:37:12 +00:00
|
|
|
return "${env:USERNAME}@$(${env:COMPUTERNAME}.ToLower())> "
|
2023-03-19 22:38:03 +00:00
|
|
|
}
|
|
|
|
} elseif ($IsLinux) {
|
2023-09-15 10:37:12 +00:00
|
|
|
return "$(id -un)@$(hostname -s)> "
|
2023-03-19 22:38:03 +00:00
|
|
|
} else {
|
2023-09-15 10:37:12 +00:00
|
|
|
return "PS> "
|
2022-09-08 15:10:57 +00:00
|
|
|
}
|
2022-01-18 11:48:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 11:51:03 +00:00
|
|
|
function ADUserInfo {
|
2023-06-26 14:16:30 +00:00
|
|
|
param (
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$User
|
2022-03-31 11:51:03 +00:00
|
|
|
)
|
|
|
|
Import-Module ActiveDirectory -ErrorAction Stop
|
|
|
|
$ADPropertiesCommon = @(
|
|
|
|
'SamAccountName'
|
|
|
|
'UserPrincipalName'
|
|
|
|
'DisplayName'
|
|
|
|
'Enabled'
|
|
|
|
'PasswordExpired'
|
|
|
|
'LockedOut'
|
|
|
|
'CannotChangePassword'
|
|
|
|
'PasswordNeverExpires'
|
|
|
|
'GivenName'
|
|
|
|
'Surname'
|
|
|
|
'DistinguishedName'
|
|
|
|
'EmployeeID'
|
|
|
|
'Title'
|
|
|
|
'Department'
|
|
|
|
'Created'
|
|
|
|
'Modified'
|
2022-04-01 13:35:40 +00:00
|
|
|
'PasswordLastSet'
|
2022-03-31 11:51:03 +00:00
|
|
|
)
|
|
|
|
$ADPropertiesGetOnly = @(
|
|
|
|
'msDS-UserPasswordExpiryTimeComputed'
|
|
|
|
)
|
|
|
|
$ADPropertiesPrintOnly = @(
|
2023-06-26 14:16:30 +00:00
|
|
|
@{Name = "PasswordExpiresDate"; Expression = { [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed") } }
|
2022-03-31 11:51:03 +00:00
|
|
|
)
|
|
|
|
$ADPropertiesGet = $ADPropertiesCommon + $ADPropertiesGetOnly
|
|
|
|
$ADPropertiesPrint = $ADPropertiesCommon + $ADPropertiesPrintOnly
|
|
|
|
Get-ADUser -Properties $ADPropertiesGet -Identity $User | Select-Object -Property $ADPropertiesPrint
|
|
|
|
}
|
|
|
|
|
2023-10-03 07:55:07 +00:00
|
|
|
function mkcd {
|
2023-06-26 14:16:30 +00:00
|
|
|
param (
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$Path
|
2023-05-09 13:43:56 +00:00
|
|
|
)
|
|
|
|
New-Item -ItemType Directory -Path $Path
|
|
|
|
Set-Location -Path $Path
|
|
|
|
}
|
|
|
|
|
2023-10-03 07:55:07 +00:00
|
|
|
if ($IsWindows -or ($env:OS -eq "Windows_NT")) {
|
|
|
|
function who {
|
|
|
|
& "$env:SystemRoot\System32\query.exe" user
|
|
|
|
}
|
2024-01-11 11:30:53 +00:00
|
|
|
|
|
|
|
# Drop elevation privileges.
|
|
|
|
$env:__COMPAT_LAYER = "RunAsInvoker"
|
2023-10-03 07:55:07 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 14:09:35 +00:00
|
|
|
if (!(Get-Command Get-Uptime -ErrorAction SilentlyContinue)) {
|
|
|
|
function Get-Uptime {
|
|
|
|
Get-WmiObject Win32_OperatingSystem | Select-Object @{LABEL='LastBootUpTime';EXPRESSION={$_.ConvertToDateTime($_.LastBootUpTime)}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-17 08:02:51 +00:00
|
|
|
# Force UTF-8 output.
|
|
|
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
|
2024-01-29 15:27:01 +00:00
|
|
|
# Try upgrading the default version of PSReadLine to something newer.
|
|
|
|
if ((Get-Module PSReadline).Version -le [Version]"2.0.0.0") {
|
|
|
|
try {
|
|
|
|
Write-Host "PSReadLine <= 2.0.0.0. Trying to upgrade..."
|
|
|
|
Install-Module -Scope CurrentUser -Name PSReadLine -Force -ErrorAction SilentlyContinue
|
|
|
|
Write-Host "PSReadLine upgraded. Restart PowerShell to load it."
|
|
|
|
} catch {
|
|
|
|
Write-Host "Failed upgrading PSReadline."
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 11:48:49 +00:00
|
|
|
Set-PSReadlineOption -BellStyle None
|
|
|
|
Set-PSReadlineOption -EditMode Emacs
|
|
|
|
Set-PSReadlineKeyHandler -Key Tab -Function Complete
|
|
|
|
Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock {
|
2022-03-02 11:56:41 +00:00
|
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward()
|
|
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
|
2022-01-18 11:48:49 +00:00
|
|
|
}
|
|
|
|
Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock {
|
2022-03-02 11:56:41 +00:00
|
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward()
|
|
|
|
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
|
2022-01-18 11:48:49 +00:00
|
|
|
}
|
|
|
|
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
|
2023-07-14 12:04:31 +00:00
|
|
|
Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function SelfInsert
|
2022-03-02 11:56:41 +00:00
|
|
|
|
2023-06-26 14:16:42 +00:00
|
|
|
# Keep this at the end.
|
|
|
|
$LocalProfilePath = Join-Path -Path "$PSScriptRoot" -ChildPath "local.ps1"
|
|
|
|
if (Test-Path $LocalProfilePath -PathType Leaf) {
|
|
|
|
. $LocalProfilePath
|
|
|
|
}
|