Compare commits

...

4 Commits

Author SHA1 Message Date
lub c1c77bd7c1 use variable insted of tilda
for better compatibility
2 weeks ago
lub b1015a15ef implement wsh
also make other parts of profile.ps1 wsh compatible
2 weeks ago
lub 8336f9bddd typo 2 weeks ago
lub 57eebd6429 remove pwsh version check
enough muscle memory has been built
2 weeks ago

@ -1,29 +1,36 @@
#region keybindings
Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadlineKeyHandler -Key Ctrl+d -Function ViExit
if (Get-Module PSReadLine) {
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
#region prompt
# 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
# depending on elevated permissions change the delimiter
# prefix variables with random strings to avaid collissions
function prompt {
#shorten path with tilde if possible
#uses .Replace() to prevent regex
$cwd = (Get-Location).Path.Replace($HOME,'~')
$identity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if($identity.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$delimiter = '#'
} else {
$delimiter = '$'
}
'[{0}@{1} {2}]{3} ' -f $username,$computername,$cwd,$delimiter
# shorten path with tilde if possible
# uses .Replace() to prevent regex
$homePath = if ($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
}
#endregion prompt
function Get-BADUser {
param (
[Parameter(Mandatory=$true,
@ -83,7 +90,7 @@ function Get-BADPrincipalGroupMembership {
)
process {
write-host $ADObject
Write-Host $ADObject
$server = $ADObject.DistinguishedName.Split(',DC=')[-2,-1] -join '.'
$ADObject | Get-ADPrincipalGroupMembership -Server $server
@ -114,14 +121,30 @@ function Get-Feierabend {
$Begin.AddHours($Hours).AddMinutes($Minutes).Add($PauseEnd - $PauseStart)
}
function fsh {
function wsh {
param (
[string]$ComputerName
[Parameter(Mandatory, Position = 0)]
[String]
$ComputerName
)
$host.UI.RawUI.WindowTitle = $ComputerName
Enter-PSSession @PSBoundParameters @args
$profileContent = (
(
$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 {
param (
@ -143,8 +166,3 @@ function watch {
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