Advertisement
Guest User

Fancy PowerShell Prompt

a guest
Feb 24th, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function prompt {
  2.     if(
  3.         (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())
  4.         ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
  5.             $IsAdmin = $true
  6.     } else {
  7.         $IsAdmin = $false
  8.     }
  9.  
  10.     $UserDomain = $Env:COMPUTERNAME.ToLower()
  11.     $UserName = $Env:USERNAME
  12.  
  13.     $CurrentPath = $Pwd.ToString()
  14.  
  15.     $CurrentPath = $CurrentPath.Replace($Env:USERPROFILE, "~")
  16.  
  17.     $Host.UI.RawUI.WindowTitle = "$Env:USERNAME@$UserDomain $CurrentPath - PowerShell"
  18.  
  19.     if ($IsAdmin) {
  20.         $Host.UI.RawUI.WindowTitle += ' (Administrator)'
  21.         $ForegroundColor = "Red"
  22.     } else {
  23.         $ForegroundColor = "DarkGray"
  24.     }
  25.  
  26.     $CurrentDirectory = $CurrentPath.split('\')[-1]
  27.  
  28.     Write-Host "$UserName@${UserDomain}:" -ForegroundColor $ForegroundColor -NoNewline
  29.     Write-Host $CurrentDirectory -ForegroundColor Gray -NoNewline
  30.     Write-Host ">" -ForegroundColor $ForegroundColor -NoNewline
  31.     return " "
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement