Check whether Powershell is running with administrator privileges
- Get link
- X
- Other Apps
In the previous post, I was using Oh My Posh to apply a theme to Powershell, but the prompt line was pushed back when I 'Run as Administrator'. Let me summarize how I solved this in my own way.
Customizing Windows Powershell
For example:
| When run with administrator privileges, one line is pushed |
So, I decided to remove the time and speed display on the right side when 'Run as administrator' in the Powershell profile.
1. Copy the existing theme file and call the theme when ‘Run as administrator’.
2. Remove the right attribute from the copied theme file and save it as a separate theme file.
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{ "alignment": "right", "segments": [ { "background": "#003543", "foreground": "#ffffff", "style": "plain", "template": " \ue641 {{ .CurrentDate | date .Format }} ", "type": "time" }, { "background": "#83769c", "foreground": "#ffffff", "properties": { "always_enabled": true }, "style": "plain", "template": " \ueba2 {{ .FormattedMs }} ", "type": "executiontime" } ], "type": "rprompt" },
{
"alignment": "left",
"segments": [
{
"background": "#61AFEF",
"foreground": "#ffffff",
"properties": {
"display_host": false
},
"style": "diamond",
"template": "{{if .Root}} \uf0e7 austin {{else}} austin {{end}}",
"trailing_diamond": "\ue0b0",
"type": "session"
},
{
"background": "#C678DD",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"folder_icon": "\uf115",
"folder_separator_icon": " \ue0b1 ",
"max_depth": 2,
"style": "agnoster_short"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#95ffa4",
"foreground": "#193549",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ .HEAD }} ",
"type": "git"
}
],
"type": "prompt"
}
],
"console_title_template": "{{if .Root}} \u26a1 {{end}}austin \u2794 📁{{.Folder}}",
"final_space": true,
"version": 2
}
function isAdminMode() {
return ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if(isAdminMode){
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\austin.omp.admin.json" | Invoke-Expression
}else{
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\austin.omp.json" | Invoke-Expression
}
- Get link
- X
- Other Apps
Comments
Post a Comment