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")) {
|
|
|
|
[string]$monoPrompt = ""
|
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-03-19 22:38:03 +00:00
|
|
|
$monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# "
|
2022-03-02 11:56:41 +00:00
|
|
|
} else {
|
2023-03-19 22:38:03 +00:00
|
|
|
$monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> "
|
2022-03-02 11:56:41 +00:00
|
|
|
}
|
2023-03-19 22:38:03 +00:00
|
|
|
if ($PSVersionTable.PSVersion -gt [System.Version]"6.0") {
|
|
|
|
"`e[1m" + $monoPrompt + "`e[0m"
|
|
|
|
} else {
|
|
|
|
$monoPrompt
|
|
|
|
}
|
|
|
|
} elseif ($IsLinux) {
|
2022-03-02 11:56:41 +00:00
|
|
|
"`e[1m" + $(id -un) + "@" + $(hostname -s) + "> `e[0m"
|
2023-03-19 22:38:03 +00:00
|
|
|
} else {
|
2022-09-08 15:10:57 +00:00
|
|
|
"PS> "
|
|
|
|
}
|
2022-01-18 11:48:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 11:51:03 +00:00
|
|
|
function ADUserInfo {
|
|
|
|
Param (
|
|
|
|
[Parameter(Mandatory=$true)] [string]$User
|
|
|
|
)
|
|
|
|
Import-Module ActiveDirectory -ErrorAction Stop
|
|
|
|
$ADPropertiesCommon = @(
|
|
|
|
'SamAccountName'
|
|
|
|
'UserPrincipalName'
|
|
|
|
'DisplayName'
|
|
|
|
'Enabled'
|
|
|
|
'PasswordExpired'
|
|
|
|
'LockedOut'
|
|
|
|
'CannotChangePassword'
|
|
|
|
'PasswordNeverExpires'
|
|
|
|
'GivenName'
|
|
|
|
'Surname'
|
|
|
|
'DistinguishedName'
|
|
|
|
'EmployeeID'
|
|
|
|
'PersonalPager'
|
|
|
|
'Title'
|
|
|
|
'Division'
|
|
|
|
'Department'
|
|
|
|
'Created'
|
|
|
|
'Modified'
|
2022-04-01 13:35:40 +00:00
|
|
|
'PasswordLastSet'
|
2022-03-31 11:51:03 +00:00
|
|
|
)
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
2023-05-09 13:43:56 +00:00
|
|
|
Function mkcd {
|
|
|
|
Param (
|
|
|
|
[Parameter(Mandatory=$true,Position=0)] [string]$Path
|
|
|
|
)
|
|
|
|
New-Item -ItemType Directory -Path $Path
|
|
|
|
Set-Location -Path $Path
|
|
|
|
}
|
|
|
|
|
2022-01-18 11:48:49 +00:00
|
|
|
Set-Alias -Name json -Value ConvertTo-Json
|
|
|
|
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 Shift+Spacebar -Function SelfInsert
|
|
|
|
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
|
2022-03-02 11:56:41 +00:00
|
|
|
|
2022-03-02 13:00:08 +00:00
|
|
|
if ($PSVersionTable.PSVersion -ge [System.Version]"7.2") {
|
2022-03-02 12:49:23 +00:00
|
|
|
$AnsiReset = "`e[0m"
|
|
|
|
Set-PSReadLineOption -Colors @{
|
2022-03-02 11:56:41 +00:00
|
|
|
Default = $AnsiReset;
|
2022-03-02 12:49:23 +00:00
|
|
|
Command = $AnsiReset;
|
|
|
|
Comment = $AnsiReset;
|
|
|
|
ContinuationPrompt = $AnsiReset;
|
|
|
|
Emphasis = $AnsiReset;
|
|
|
|
Error = $AnsiReset;
|
|
|
|
InlinePrediction = $AnsiReset;
|
|
|
|
Keyword = $AnsiReset;
|
|
|
|
Member = $AnsiReset;
|
|
|
|
Number = $AnsiReset;
|
|
|
|
Operator = $AnsiReset;
|
|
|
|
Parameter = $AnsiReset;
|
|
|
|
Selection = $AnsiReset;
|
|
|
|
String = $AnsiReset;
|
|
|
|
Type = $AnsiReset;
|
|
|
|
Variable = $AnsiReset;
|
|
|
|
}
|
2022-03-02 11:56:41 +00:00
|
|
|
}
|