import-module z Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-a4faccd\src\posh-git.psd1' function prompt { $shortenedPath = (Get-ShortenedPromptPath $((pwd).Path)) $host.UI.RawUI.WindowTitle = ("PS " + $shortenedPath) $colorHostFg = [ConsoleColor]::White $colorLocation = [ConsoleColor]::Cyan if (Test-IsAdmin) { $colorHostBg = [ConsoleColor]::Red $host.UI.RawUI.WindowTitle += " (Admin)" } else { $colorHostBg = [ConsoleColor]::Blue } $realLASTEXITCODE = $LASTEXITCODE # Reset color, which can be messed up by Enable-GitColors # $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor Write-Host ([net.dns]::GetHostName().ToLower()) -n -f $colorHostFg -b $colorHostBg Write-Host "" $shortenedPath -n -f $colorLocation Write-VcsStatus $global:LASTEXITCODE = $realLASTEXITCODE if ($shortenedPath.length -gt 20) { Write-Host " " } else { Write-Host " " -n } return "> " } function Get-ShortenedPromptPath([string] $path) { $loc = $path.Replace($HOME, '~') return $loc } function Test-IsAdmin { try { $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $identity return $principal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ) } catch { throw "Failed to determine if the current user has elevated privileges. The error was: '{0}'." -f $_ } <# .SYNOPSIS Checks if the current Powershell instance is running with elevated privileges or not. .EXAMPLE PS C:\> Test-IsAdmin .OUTPUTS System.Boolean True if the current Powershell is elevated, false if not. #> } function Write-Centered { Param( [string] $message, [string] $fgcolor = "White") $offsetvalue = [Math]::Round(([Console]::WindowWidth / 2) + ($message.Length / 2)) Write-Host ("{0,$offsetvalue}" -f $message) -ForegroundColor $fgcolor } function Show-WelcomeMessage { Write-Centered ([net.dns]::GetHostName().ToUpper() -replace '(.)', '$1 ') -fgcolor "White" $current_date = Get-Date -Format 'D' $current_uptime = (get-date) - ([System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject win32_operatingsystem).lastbootuptime)) $uptime_string = "Up for " + ("{0:%d}d {1:%h}h {2:%m}m {3:%s}s" -f ($current_uptime, $current_uptime, $current_uptime, $current_uptime)) Write-Centered ($current_date + " | " + $uptime_string) -fgcolor "DarkGray" Write-Host "" } clear Show-WelcomeMessage