PowerShell comes with a typical immediate whose configuration is saved within the immediate operate. The excellent news is that we’re capable of change this immediate operate to go well with our wants. On this weblog submit, I’ll present you how one can change this immediate and I gives you some examples.
Topic
We’re investigating this topic:
And we’re additionally investigating the operate which is said to this default immediate:
(Get-Merchandise operate:immediate).ScriptBlock
That is the default immediate. For customizing, we have to change this default immediate.
Altering the Look of the Immediate
Listed below are 4 examples you need to use in your immediate or for additional customization.
Exhibiting the Date
operate immediate {
"$(Get-Date)> "
}
Default Immediate + Computername
operate immediate {
"PS [$env:COMPUTERNAME]> "
}
If PowerShell is began as administrator, then present [Administrator]
operate immediate {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $id
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$(if (Take a look at-Path variable:/PSDebugContext) { '[DBG]: ' }
elseif($principal.IsInRole($adminRole)) { "[ADMINISTRATOR]: " }
else { '' }
) + 'PS ' + $(Get-Location) +
$(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
}
Exhibiting the Username
operate immediate {
"PS [$env:USERNAME]> "
}
I hope I used to be capable of spark some concepts on how one can change the immediate of your PowerShell session.
In case you are questioning how one can completely implement your customized immediate take a look at my article about PowerShell Profiles: The best way to create PowerShell Profiles
Printed by