Guest User

Fancy PowerShell Prompt

a guest
Feb 24th, 2017
185
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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×