#requires -version 2.0 # ----------------------------------------------------------------------------- # Script: EverythingPrompt.ps1 # Author: Jeffery Hicks # http://jdhitsolutions.com/blog # Date: 10/29/2010 # Keywords: Prompt, WMI # Comments: # # ----------------------------------------------------------------------------- Function prompt { #add global variable if it doesn't already exist if (-Not $global:LastCheck) { $global:LastCheck=Get-Date $global:cdrive=Get-WMIObject -query "Select Freespace,Size from win32_logicaldisk where deviceid='c:'" } #only refresh disk information once every 15 minutes $min=(New-TimeSpan $Global:lastCheck).TotalMinutes if ($min -ge 15) { $global:cdrive=Get-WMIObject -query "Select Freespace,Size from win32_logicaldisk where deviceid='c:'" $global:LastCheck=Get-Date } [int]$freeMem=(Get-Wmiobject -query "Select FreeAndZeroPageListBytes from Win32_PerfFormattedData_PerfOS_Memory").FreeAndZeroPageListBytes/1mb $cpu=(gwmi win32_processor).loadpercentage $pcount=(Get-Process).Count $diskinfo="{0:N2}" -f (($global:cdrive.freespace/1gb)/($global:cdrive.size/1gb)*100) #get uptime $time=Get-WmiObject -class Win32_OperatingSystem $t=$time.ConvertToDateTime($time.Lastbootuptime) [TimeSpan]$uptime=New-TimeSpan $t $(get-date) $up="$($uptime.days)d $($uptime.hours)h $($uptime.minutes)m $($uptime.seconds)s" #$text="CPU:"+$cpu+"% Procs:"+$pcount+$diskinfo+ " "+([char]0x25b2)+$up +" "+(Get-Date -format g) $text="CPU:{0}% FreeMem:{6}MB Procs:{1} Free C:{2}% {3}{4} {5}" -f $cpu,$pcount,$diskinfo,([char]0x25b2),$up,(Get-Date -format g),$FreeMem $myPrompt=[char]0x250c $myPrompt+=([char]0x2500).ToString()*$text.length $myPrompt+=[char]0x2510 $myPrompt+="`n" $myPrompt+=([char]0x2502)+$text+([char]0x2502) $myPrompt+="`n" $myPrompt+=[char]0x2514 $myPrompt+=([char]0x2500).ToString()*$text.length $myPrompt+=[char]0x2518 Write-Host $myPrompt -fore Green #get history ID $hid=(Get-History -count 1).id+1 Write-Host "$hid PS>" -nonewline #set the PowerShell session time, computername and current location in the title bar #get start time for the current PowerShell session #$pid is a special variable for the current PowerShell process ID [datetime]$psStart=(get-Process -id $pid).StartTime $ts=(Get-Date) - $psStart #strip off the millisecond part with Substring(). The #millisecond part will come after the last period $s=$ts.ToString() $elapsed=$s.Substring(0,$s.LastIndexOf(".")) $title="[{0}{1}{2}] {3}" -f $elapsed,([char]0x25ba),$env:computername,(Get-Location) $host.ui.rawui.WindowTitle=$title #the function's actual return is nothing return " " }