Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. $PromptENV = 'Prod'
  2. $Role = "User"
  3. $IsAdmin = $False
  4.  
  5. function Test-Admin{
  6. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  7. $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  8. }
  9.  
  10. function Write-ENVPrompt{
  11. Write-Host "[" -NoNewline
  12. if($PromptENV -eq 'Prod'){
  13. $Color = 'Red'
  14. }elseif($PromptENV -eq 'Dev'){
  15. $Color = 'Yellow'
  16. }else{
  17. $Color = 'Gray'
  18. }
  19. Write-Host -Object $PromptENV -NoNewline -ForegroundColor $Color
  20. Write-Host "]" -NoNewline
  21. Return "[$PromptENV]"
  22. }
  23.  
  24. function Write-PSDrivePrompt{
  25. $DriveName = $ExecutionContext.SessionState.Path.CurrentLocation.Drive.Name
  26. Write-host -Object $DriveName -ForegroundColor Cyan -NoNewline
  27. Write-host -Object $ExecutionContext.SessionState.Path.CurrentLocation.Path.Replace($DriveName,'') -NoNewline
  28. Return $ExecutionContext.SessionState.Path.CurrentLocation.Path
  29. }
  30.  
  31. function Write-NetworkDrivePrompt{
  32. $PromptServerpath = ($ExecutionContext.SessionState.Path.CurrentLocation.ProviderPath -split "\\")
  33. Write-Host "\\" -NoNewline
  34. Write-Host $PromptServerPath[2] -NoNewline -ForegroundColor Cyan
  35. $PromptPath = $PromptServerpath |Select -Skip 3
  36. Write-Host "\$($PromptPath -join "\")" -NoNewline
  37. Return $ExecutionContext.SessionState.Path.CurrentLocation.ProviderPath
  38. }
  39.  
  40. function Write-RolePrompt{
  41. Write-Host "[" -NoNewline
  42. if($IsAdmin){
  43. Write-Host -Object $Role -NoNewline -ForegroundColor Red
  44. }else{
  45. Write-Host -Object $Role -NoNewline -ForegroundColor Green
  46. }
  47. Write-Host "]" -NoNewline
  48. Return "[$Role]"
  49. }
  50.  
  51. if(Test-Admin){
  52. $Role = "Admin"
  53. $IsAdmin = $True
  54. }
  55.  
  56. Write-Host -ForegroundColor $ForeGroundColor "************** Welcome BoredComputerGuy **************"
  57.  
  58. function prompt{
  59. $RoleTitle = Write-RolePrompt
  60. $ENVTitle = Write-ENVPrompt
  61. Write-Host -Object "PS " -NoNewline
  62. $PromptCurrentLocation = $ExecutionContext.SessionState.Path.CurrentLocation
  63. if($Null -eq $PromptCurrentLocation.Drive -and $PromptCurrentLocation.Path -like "Microsoft.PowerShell.Core\FileSystem::\\*"){
  64. $PathTitle = Write-NetworkDrivePrompt
  65. }elseif($PromptCurrentLocation.Drive.Name.Length -gt 1){
  66. $PathTitle = Write-PSDrivePrompt
  67. }else{
  68. $PathTitle = "$($ExecutionContext.SessionState.Path.CurrentLocation)"
  69. Write-Host -Object $PathTitle -NoNewline
  70. }
  71.  
  72. "$('>' * ($nestedPromptLevel + 1)) "
  73. $host.ui.RawUI.WindowTitle = "$RoleTitle $ENVTitle PS $PathTitle"
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement