Image
This article will summarize the development of Add-Ins for Outlook.  Use the basic template using Yeoman and Yeoman Generator. Development environment OS: Windows 11 .Net version: 8.0 Development tool: Visual Studio Code Node.js version: 18.20.4 Yeoman version: 5.0.0 Development language: React, Typescript

Check whether Powershell is running with administrator privileges

 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
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
}


3. Check ‘Run as administrator’ in Powershell profile and add conditional statement

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
}


4. Run Powershell with administrator privileges

Run as administrator
Run as administrator

General
General







Comments

Popular posts from this blog

Setting up Windows Powershell with Oh-My-Posh

[NETSDK1136] the target platform must be set to windows