Compare commits

..

No commits in common. 'c1c77bd7c1b35e5ddf73dcb3349eb4fdcf434377' and '5894ceaf8373d4b8119273aeee1f378e54dcc756' have entirely different histories.

@ -1,16 +1,12 @@
#region keybindings #region keybindings
if (Get-Module PSReadLine) {
Set-PSReadlineKeyHandler -Key Tab -Function Complete Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadlineKeyHandler -Key Ctrl+d -Function ViExit Set-PSReadlineKeyHandler -Key Ctrl+d -Function ViExit
}
#endregion keybindings #endregion keybindings
#region prompt #region prompt dependencies
#set part of the prompt beforehand to optimize the prompt function #set part of the prompt beforehand to optimize the prompt function
#depending on elevated permissions change the delimiter #depending on elevated permissions change the delimiter
# prefix variables with random strings to avaid collissions
function prompt {
$identity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() $identity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if($identity.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { if($identity.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$delimiter = '#' $delimiter = '#'
@ -18,19 +14,16 @@ function prompt {
$delimiter = '$' $delimiter = '$'
} }
$username = $env:USERNAME.ToLower()
$computername = $env:COMPUTERNAME.ToLower()
#endregion prompt dependencies
function prompt {
#shorten path with tilde if possible #shorten path with tilde if possible
#uses .Replace() to prevent regex #uses .Replace() to prevent regex
$homePath = if ($HOME) { $cwd = (Get-Location).Path.Replace($HOME,'~')
$HOME
} elseif ($env:USERPROFILE) {
$env:USERPROFILE
}
$cwd = (Get-Location).Path.Replace($homePath,'~')
'[{0}@{1} {2}]{3} ' -f $env:USERNAME.ToLower(),$env:COMPUTERNAME.ToLower(),$cwd,$delimiter '[{0}@{1} {2}]{3} ' -f $username,$computername,$cwd,$delimiter
} }
#endregion prompt
function Get-BADUser { function Get-BADUser {
param ( param (
[Parameter(Mandatory=$true, [Parameter(Mandatory=$true,
@ -90,7 +83,7 @@ function Get-BADPrincipalGroupMembership {
) )
process { process {
Write-Host $ADObject write-host $ADObject
$server = $ADObject.DistinguishedName.Split(',DC=')[-2,-1] -join '.' $server = $ADObject.DistinguishedName.Split(',DC=')[-2,-1] -join '.'
$ADObject | Get-ADPrincipalGroupMembership -Server $server $ADObject | Get-ADPrincipalGroupMembership -Server $server
@ -121,30 +114,14 @@ function Get-Feierabend {
$Begin.AddHours($Hours).AddMinutes($Minutes).Add($PauseEnd - $PauseStart) $Begin.AddHours($Hours).AddMinutes($Minutes).Add($PauseEnd - $PauseStart)
} }
function wsh { function fsh {
param ( param (
[Parameter(Mandatory, Position = 0)] [string]$ComputerName
[String]
$ComputerName
) )
$host.UI.RawUI.WindowTitle = $ComputerName $host.UI.RawUI.WindowTitle = $ComputerName
$profileContent = ( Enter-PSSession @PSBoundParameters @args
(
$PROFILE | Get-Member | Where-Object MemberType -eq 'NoteProperty' | ForEach-Object {
Get-Content $PROFILE.($_.Name) -ErrorAction SilentlyContinue
}
) | Where-Object {$_ -notmatch '^(#|$)'}
) -join "`n"
$scriptBlock = [scriptblock]::Create($profileContent)
if (!($session = Get-PSSession -ComputerName $ComputerName -Name 'wsh*' -ErrorAction SilentlyContinue | Where-Object Availability -eq 'Available' | Select-Object -First 1)) {
$session = New-PSSession -ComputerName $ComputerName -Name ('wsh'+(Get-Random))
Invoke-Command -Session $session -Command $scriptBlock
Invoke-Command -Session $session -Command {Set-Location $env:USERPROFILE}
}
Enter-PSSession $session
} }
function watch { function watch {
param ( param (
@ -166,3 +143,8 @@ function watch {
Start-Sleep -Seconds $n Start-Sleep -Seconds $n
} }
} }
#check for old version
if($PSVersionTable.PSVersion.Major -le 5){
Write-Host -ForegroundColor Red 'start pwsh instead of powershell'
}
Loading…
Cancel
Save