[Hilfe] Die PowerShell so wie CMD anpassen!
- DK2000
- Legende

- Beiträge: 11153
- Registriert: 03.04.2018, 00:07
- Hat sich bedankt: 299 Mal
- Danke erhalten: 1012 Mal
- Gender:
Re: [Hilfe] Die PowerShell so wie CMD anpassen!
Die settings.json hat mit der PowerShell so weit nichts zu tun. Die Datei ist nur für winget.
Das Nachfolgende bezieht sich jetzt hauptsächlich auf die PowerShell 7.6 als MSIX-Installation.
Die powershell.config.json kommt hier hin:
Das ist "CurrentUser (per-user)" Konfiguration. Bei der "AllUsers (shared)" bin ich mir gerade nicht sicher. Diese in $PSHome zu erstellen, dürfte schwierig werden und ist dann wohl auch nicht permanent. In der Doku steht da jedenfalls noch nichts Neues dazu.
In der Datei steht bei mir aber nur folgendes drin:
Ob der Eintrag für "PSCommandNotFoundSuggestion" noch aktuell ist, weiß ich gerade nicht. Kann sein, dass das in die normalen Features der PowerShell übergegangen ist. Get-ExperimentalFeature zeigt das jedenfalls nicht mehr an.
Module werden hier installiert:
Wie gesagt, bei mir hat das alles so weit geklappt. Musste da in der Richtung nicht ändern. Lediglich im Terminal für meine Profile musste ich den Pfad zur pwsh.exe anpassen:
Aber das war es auch schon.
PSReadline muss weder aktualisiert noch importiert werden. Die 7.6 kommt mit der aktuellen Version 2.4.5 daher. Importieren muss man die auch nicht, da sie automatisch geladen wird. Ist ja schließlich der Standard-Interpreter für die Eingabezeile.
Und was den CompletionPredictor angeht, so habe ich da nur eingegeben (in der PowerShell 7.6):
Die PowerShell Gallery hattest Du vorher schon als vertrauenswürdig eingestuft?
Muss man nicht zwingend machen, aber die Frage ob ich der wirklich vertraue oder nicht, ging mir irgendwann mal auf den Keks.
Ich hoffe mal, dass das so halbwegs verständlich war. Wenn nicht, einfach nachragen. Wie gesagt, bei mir musste ich da nichts weiter anpassen, bis auf dem Pfad in meinen Profilen im Terminal.
Das Nachfolgende bezieht sich jetzt hauptsächlich auf die PowerShell 7.6 als MSIX-Installation.
Die powershell.config.json kommt hier hin:
Code: Alles auswählen
C:\Users\<Benutzername>l\Documents\PowerShellIn der Datei steht bei mir aber nur folgendes drin:
Code: Alles auswählen
{
"Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned",
"ExperimentalFeatures": [
"PSCommandNotFoundSuggestion"
]
}Module werden hier installiert:
Code: Alles auswählen
-Scope User : C:\Users\<Benutzername>l\Documents\PowerShell
-Scope AllUsers : C:\Program Files\PowerShellCode: Alles auswählen
"C:\Users\<Benutzer>\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe" -NoLogoPSReadline muss weder aktualisiert noch importiert werden. Die 7.6 kommt mit der aktuellen Version 2.4.5 daher. Importieren muss man die auch nicht, da sie automatisch geladen wird. Ist ja schließlich der Standard-Interpreter für die Eingabezeile.
Und was den CompletionPredictor angeht, so habe ich da nur eingegeben (in der PowerShell 7.6):
Code: Alles auswählen
Install-Module -Name CompletionPredictor -Force -Scope AllUsers -Verbose Code: Alles auswählen
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted Ich hoffe mal, dass das so halbwegs verständlich war. Wenn nicht, einfach nachragen. Wie gesagt, bei mir musste ich da nichts weiter anpassen, bis auf dem Pfad in meinen Profilen im Terminal.
-
Tante Google
- Mira Bellenbaum
- Nachwuchs

- Beiträge: 65
- Registriert: 21.05.2022, 13:38
- Hat sich bedankt: 9 Mal
- Danke erhalten: 5 Mal
Re: [Hilfe] Die PowerShell so wie CMD anpassen!
@DK2000
Ich danke Dir ganz, ganz herzlichst für diese wunderbare Anleitung.
Irgendwie hatte ich es auch ohne diese hinbekommen, wusste jetzt nur nicht mehr wie!!!
Habe es kontrolliert, und irgendwie muss ich es wohl so gemacht haben!
Das Modul "CompletionPredictor" habe ich auch, was weiß ich, installieren können,
somit musste ich es in der "ps1" nicht mehr auskommentieren.
Ich vertraue Dir, nur wozu ist das da?
Es funktionierte auch so alles.
Und so als Backup poste ich hier auch mal meine „Microsoft.PowerShell_profile.ps1“,
die auch da hingehört:
So, hier nun die „Microsoft.PowerShell_profile.ps1“:
Ich danke Dir ganz, ganz herzlichst für diese wunderbare Anleitung.
Irgendwie hatte ich es auch ohne diese hinbekommen, wusste jetzt nur nicht mehr wie!!!
Habe es kontrolliert, und irgendwie muss ich es wohl so gemacht haben!
Das Modul "CompletionPredictor" habe ich auch, was weiß ich, installieren können,
somit musste ich es in der "ps1" nicht mehr auskommentieren.
Ich vertraue Dir, nur wozu ist das da?
Es funktionierte auch so alles.
Und so als Backup poste ich hier auch mal meine „Microsoft.PowerShell_profile.ps1“,
die auch da hingehört:
Code: Alles auswählen
C:\Users\<Benutzername>l\Documents\PowerShellCode: Alles auswählen
$os = [PSCustomObject]@{
Caption = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName
}
$reg = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$branch = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\WindowsSelfHost\UI\Selection" -ErrorAction SilentlyContinue).UIBranch
$branchMap = @{
"ReleasePreview" = "Release Preview"
"Beta" = "Beta Channel"
"Dev" = "Experimental"
"CanaryChannel" = "Future Platforms"
}
if ($branch -eq $null) {
$OSFlightBranch = "Retail"
} else {
$OSFlightBranch = $branchMap[$branch]
if ($OSFlightBranch -eq $null) {
$OSFlightBranch = $branch
}
}
$OSHostVersion = "{0}, Version {1} ({2}.{3}), {4}" -f $os.Caption, $reg.DisplayVersion, $reg.CurrentBuild, $reg.UBR, $OSFlightBranch
Write-Host "PowerShell [Version"$PSVersionTable.PSVersion"`b] - $OSHostVersion"
Write-Host "Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten."
if (($PSVersionTable.PSVersion).Major -gt '5') {
$ESC = "`e"
$PSStyle.FileInfo.Directory = "$ESC[38;5;32m"
Import-Module -Name CompletionPredictor
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
}
else {
$ESC = "$([char]0x1b)"
Set-PSReadLineOption -PredictionSource History
}
$FormatEnumerationLimit = -1
$PSReadLineOptions = @{
MaximumHistoryCount = 4096
HistorySaveStyle = "SaveIncrementally"
HistoryNoDuplicates = $true
HistorySearchCaseSensitive = $false
HistorySearchCursorMovesToEnd = $true
PredictionViewStyle = "ListView"
EditMode = "Windows"
ShowToolTips = $true
Colors = @{
Operator = "#FF79C6"
Parameter = "#FF79C6"
Command = "#BD93F9"
# HIER DIE NEUEN FARBEN EINFÜGEN:
# InlinePrediction = "$([char]0x1b)[38;5;244m$([char]0x1b)[3m"
# ListPrediction = "$([char]0x1b)[38;5;242m"
# ListPredictionSelected = "$([char]0x1b)[48;5;238m$([char]0x1b)[38;5;255m"
}
}
Set-PSReadLineOption @PSReadLineOptions
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
function prompt {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
if ($principal.IsInRole($adminRole)) { $adminfgc = "Red" }
else { $adminfgc = $host.ui.rawui.ForegroundColor }
# NEU !!
$currentDir = (Get-Location).Path
if ($currentDir.Contains($HOME)) {
$currentDir = $currentDir.Replace($HOME, "~")
}
Switch ((Get-Location).Provider.Name) {
"FileSystem" { $fgc = "Green" }
"Registry" { $fgc = "Magenta" }
"Environment" { $fgc = "Yellow" }
"Certificate" { $fgc = "Darkcyan" }
"Function" { $fgc = "Gray" }
"Alias" { $fgc = "Darkgray" }
"variable" { $fgc = "Darkgreen" }
Default { $fgc = $host.ui.rawui.ForegroundColor }
}
Write-Host "`n> " -nonewline -ForegroundColor $adminfgc
Write-Host "[$($currentDir)]" -ForegroundColor $fgc
Write-Output "$('$' * ($nestedPromptLevel + 1)) "
}
Set-Location C:\
- Mira Bellenbaum
- Nachwuchs

- Beiträge: 65
- Registriert: 21.05.2022, 13:38
- Hat sich bedankt: 9 Mal
- Danke erhalten: 5 Mal
Re: [Hilfe] Die PowerShell so wie CMD anpassen!
Nachtrag!
Ich habe mal mit den Farben gespielt und auch auf Hex umgestellt.
Ist zwar noch nicht "perfekt", aber es ist bunt
Ich habe mal mit den Farben gespielt und auch auf Hex umgestellt.
Ist zwar noch nicht "perfekt", aber es ist bunt
Code: Alles auswählen
# Systeminformationen auslesen (unverändert)
$os = [PSCustomObject]@{
Caption = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName
}
$reg = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$branch = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\WindowsSelfHost\UI\Selection" -ErrorAction SilentlyContinue).UIBranch
$branchMap = @{
"ReleasePreview" = "Release Preview"
"Beta" = "Beta Channel"
"Dev" = "Experimental"
"CanaryChannel" = "Future Platforms"
}
if ($branch -eq $null) {
$OSFlightBranch = "Retail"
} else {
$OSFlightBranch = $branchMap[$branch]
if ($OSFlightBranch -eq $null) {
$OSFlightBranch = $branch
}
}
#$OSHostVersion = "{0}, Version {1} ({2}.{3}), {4}" -f $os.Caption, $reg.DisplayVersion, $reg.CurrentBuild, $reg.UBR, $OSFlightBranch
$OSHostVersion = "{0}, Version {1}" -f $os.Caption, $reg.DisplayVersion, $reg.CurrentBuild, $reg.UBR, $OSFlightBranch
# ab PowerShell 7.2+ (Moderne Konsole)
if (($PSVersionTable.PSVersion).Major -gt '5') {
# 1. Farben in funktionierende ANSI-Steuercodes umwandeln
$ansiText1 = $PSStyle.Foreground.FromRgb("#ffa500")
$ansiText2 = $PSStyle.Foreground.FromRgb("#ffff00")
$ansiText3 = $PSStyle.Foreground.FromRgb("#eea9b8")
$ansiOrdner = $PSStyle.Foreground.FromRgb("#00a2ff")
$reset = $PSStyle.Reset
# 2. Begrüßungstext formatiert mit deiner Hex-Farbe ausgeben
Write-Host "${ansiText1}PowerShell Version $($PSVersionTable.PSVersion)${reset} - ${ansiText2}$OSHostVersion${reset}"
Write-Host "${ansiText3}Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.${reset}"
# 3. Ordnerfarbe für 'ls' / 'dir' auf deinen Hex-Code umstellen
$PSStyle.FileInfo.Directory = $ansiOrdner
Import-Module -Name CompletionPredictor -ErrorAction SilentlyContinue
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
}
# Fallback für die alte Windows PowerShell 5.1
else {
# Da PS 5.1 kein True-Color/Hex kann, nutzen wir hier ein normales Cyan als Fallback
Write-Host "PowerShell [Version $($PSVersionTable.PSVersion)] - $OSHostVersion" -ForegroundColor Cyan
Write-Host "Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten."
Set-PSReadLineOption -PredictionSource History
}
$FormatEnumerationLimit = -1
$PSReadLineOptions = @{
MaximumHistoryCount = 4096
HistorySaveStyle = "SaveIncrementally"
HistoryNoDuplicates = $true
HistorySearchCaseSensitive = $false
HistorySearchCursorMovesToEnd = $true
PredictionViewStyle = "ListView"
EditMode = "Windows"
ShowToolTips = $true
Colors = @{
# ContinuationPrompt: The color of the continuation prompt.
# Emphasis: The emphasis color. For example, the matching text when searching history.
Emphasis = "#BD93F9"
# Error: The error color. For example, in the prompt.
Error = "#ff0000"
# Selection: The color to highlight the menu selection or selected text.
Selection = "#00ffe1"
# Default: The default token color.
Default = "#ca4eff" # "#ffff00"
# Comment: The comment token color.
Comment = "#ffbb00"
# Keyword: The keyword token color.
Keyword = "#00ffe1"
# String: The string token color.
String = "#00ffe1"
# Operator: The operator token color.
Operator = "#FF79C6"
# Variable: The variable token color.
Variable = "#00ffe1"
# Command: The command token color.
Command = "#00ff00" # "#BD93F9"
# Parameter: The parameter token color.
Parameter = "#ff66bd" # "#FF79C6"#ffff00
# Type: The type token color.
Type = "#00ffe1"
# Number: The number token color.
Number = "#00ffe1"
# Member: The member name token color.
Member = "#00ffe1"
# InlinePrediction: The color for the inline view of the predictive suggestion.
InlinePrediction = "$($PSStyle.Foreground.FromRgb('#9fcdff'))$($PSStyle.Italic)"
# ListPrediction: The color for the leading > character and prediction source name.
ListPrediction = "$($PSStyle.Foreground.FromRgb('#FFD700'))" # '#FFD700'
# ListPredictionSelected: The color for the selected prediction in list view.
ListPredictionSelected = "$($PSStyle.Background.FromRgb('#444444'))$($PSStyle.Foreground.FromRgb('#FFFFFF'))"
}
}
Set-PSReadLineOption @PSReadLineOptions
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
function prompt {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
if ($principal.IsInRole($adminRole)) { $adminfgc = "Red" }
else { $adminfgc = $host.ui.rawui.ForegroundColor }
# NEU !!
$currentDir = (Get-Location).Path
if ($currentDir.Contains($HOME)) {
$currentDir = $currentDir.Replace($HOME, "~")
}
Switch ((Get-Location).Provider.Name) {
"FileSystem" { $fgc = $PSStyle.Foreground.FromRgb("#7fff00") } # Knallgrün
"Registry" { $fgc = $PSStyle.Foreground.FromRgb("#ff00ff") } # Magenta
"Environment" { $fgc = $PSStyle.Foreground.FromRgb("#ffff00") } # Gelb
"Certificate" { $fgc = $PSStyle.Foreground.FromRgb("#008b8b") } # Darkcyan
"Function" { $fgc = $PSStyle.Foreground.FromRgb("#808080") } # Gray
"Alias" { $fgc = $PSStyle.Foreground.FromRgb("#a9a9a9") } # Darkgray
"variable" { $fgc = $PSStyle.Foreground.FromRgb("#006400") } # Darkgreen
Default { $fgc = "" } # Standardfarbe der Konsole
}
Write-Host "`n> " -nonewline -ForegroundColor $adminfgc
Write-Host "${fgc}[$($currentDir)]$($PSStyle.Reset)"
Write-Output "$('$' * ($nestedPromptLevel + 1)) "
}
#Set-Location C:\
Set-Location
- Mira Bellenbaum
- Nachwuchs

- Beiträge: 65
- Registriert: 21.05.2022, 13:38
- Hat sich bedankt: 9 Mal
- Danke erhalten: 5 Mal
Re: [Hilfe] Die PowerShell so wie CMD anpassen!
@DK2000
Bitte zeige mir doch Deine "Profil.ps1".
Bei Dir sind "Teile" mit Farben definiert, die bekomme ich nicht farbig!!
Bitte zeige mir doch Deine "Profil.ps1".
Bei Dir sind "Teile" mit Farben definiert, die bekomme ich nicht farbig!!
- Mira Bellenbaum
- Nachwuchs

- Beiträge: 65
- Registriert: 21.05.2022, 13:38
- Hat sich bedankt: 9 Mal
- Danke erhalten: 5 Mal
Re: [Hilfe] Die PowerShell so wie CMD anpassen!
@DK2000
Hat sich erledigt!
Ich blindes Huhn habe nicht richtig hingeschaut!!
Sorry.
Hat sich erledigt!
Ich blindes Huhn habe nicht richtig hingeschaut!!
Sorry.