Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $PromptENV = 'Prod'
- $Role = "User"
- $IsAdmin = $False
- function Test-Admin{
- $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
- $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
- }
- function Write-ENVPrompt{
- Write-Host "[" -NoNewline
- if($PromptENV -eq 'Prod'){
- $Color = 'Red'
- }elseif($PromptENV -eq 'Dev'){
- $Color = 'Yellow'
- }else{
- $Color = 'Gray'
- }
- Write-Host -Object $PromptENV -NoNewline -ForegroundColor $Color
- Write-Host "]" -NoNewline
- Return "[$PromptENV]"
- }
- function Write-PSDrivePrompt{
- $DriveName = $ExecutionContext.SessionState.Path.CurrentLocation.Drive.Name
- Write-host -Object $DriveName -ForegroundColor Cyan -NoNewline
- Write-host -Object $ExecutionContext.SessionState.Path.CurrentLocation.Path.Replace($DriveName,'') -NoNewline
- Return $ExecutionContext.SessionState.Path.CurrentLocation.Path
- }
- function Write-NetworkDrivePrompt{
- $PromptServerpath = ($ExecutionContext.SessionState.Path.CurrentLocation.ProviderPath -split "\\")
- Write-Host "\\" -NoNewline
- Write-Host $PromptServerPath[2] -NoNewline -ForegroundColor Cyan
- $PromptPath = $PromptServerpath |Select -Skip 3
- Write-Host "\$($PromptPath -join "\")" -NoNewline
- Return $ExecutionContext.SessionState.Path.CurrentLocation.ProviderPath
- }
- function Write-RolePrompt{
- Write-Host "[" -NoNewline
- if($IsAdmin){
- Write-Host -Object $Role -NoNewline -ForegroundColor Red
- }else{
- Write-Host -Object $Role -NoNewline -ForegroundColor Green
- }
- Write-Host "]" -NoNewline
- Return "[$Role]"
- }
- if(Test-Admin){
- $Role = "Admin"
- $IsAdmin = $True
- }
- Write-Host -ForegroundColor $ForeGroundColor "************** Welcome BoredComputerGuy **************"
- function prompt{
- $RoleTitle = Write-RolePrompt
- $ENVTitle = Write-ENVPrompt
- Write-Host -Object "PS " -NoNewline
- $PromptCurrentLocation = $ExecutionContext.SessionState.Path.CurrentLocation
- if($Null -eq $PromptCurrentLocation.Drive -and $PromptCurrentLocation.Path -like "Microsoft.PowerShell.Core\FileSystem::\\*"){
- $PathTitle = Write-NetworkDrivePrompt
- }elseif($PromptCurrentLocation.Drive.Name.Length -gt 1){
- $PathTitle = Write-PSDrivePrompt
- }else{
- $PathTitle = "$($ExecutionContext.SessionState.Path.CurrentLocation)"
- Write-Host -Object $PathTitle -NoNewline
- }
- "$('>' * ($nestedPromptLevel + 1)) "
- $host.ui.RawUI.WindowTitle = "$RoleTitle $ENVTitle PS $PathTitle"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement