Profil erweitern¶
Erinnerung, falls wir noch keine Profilumgebung besitzen: (siehe Test-Path $PROFILE
)
Schnell eine Profildatei für den aktuellen User (CurrentUser) und den aktuellen Host (CurrentHost; also PowerShell Konsole oder ISE) erstellen:
New-Item $PROFILE -ItemType file –Force # bzw. noch genauer:
New-Item $PROFILE.CurrentUserCurrentHost -ItemType file –Force
Eine kleine Beispiel-Profildatei mit:
Anpassungen Titelleister von Host Console
Alias für notepad++
Funktion cdd (Change Directory with Dialog)
Profilbeispiel¶
1 # Beispiel Profildatei $PROFILE
2 # Title der Shell einstellen - nach Schwichtenberg
3 $WI = [System.Security.Principal.WindowsIdentity]::GetCurrent()
4 $WP = New-Object System.Security.Principal.WindowsPrincipal($wi)
5 if ($WP.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))
6 {
7 $Status = "[elevated user]"
8 }
9 else
10 {
11 $Status = "[normal User]"
12 }
13
14 $Host.UI.RawUI.WindowTitle = "PowerShell - " + [System.Environment]::UserName + " " + $Status
15
16 # Beispielalias
17 Set-Alias np++ 'C:\Program Files (x86)\Notepad++\notepad++.exe'
18
19 # Beispielfunktion cdd - Change Dir with Dialog
20 function cdd {
21 $shell = New-Object -comObject "Shell.Application"
22 $options = 0x51 # Nur Dateisystem-Ordner - inklusive Edit-Box
23 $loc = $shell.BrowseForFolder(0, "Wohin soll es gehen?", $options)
24 if($loc) {Set-Location $loc.Self.Path}
25 }
Hier lassen sich jetzt beliebig die Techniken der PowerShell (Aliase, Provider/Drives, Funktionen) integrieren.