# ----------------------------------------------------------------------------- # Script: DateTimePrompts.ps1 # Author: Jeffery Hicks # http://jdhitsolutions.com/blog # http://twitter.com/jeffhicks # Date: 10/12/2010 # Keywords: Prompt,date,location # Comments: # Don't try to run this file. Copy and paste the function you want either # into your PowerShell session or your profile. # # Learn more with a copy of Windows PowerShell 2.0: TFM (SAPIEN Press 2010) # ----------------------------------------------------------------------------- Function Prompt { "[{0} {1}]PS {2}>" -f (get-date).ToShortDateString(),(get-date).ToLongTimeString(),(get-location) } Function Prompt { #[10/12/2010 8:41:47 AM]PS C:\Users\Jeff> $dt= "[{0} {1}]" -f (get-date).toshortdatestring(),(get-date).TolongTimeString() $loc="PS {0}" -f (get-location) Write-Host $dt -NoNewline -ForegroundColor Yellow write-host $loc -NoNewline #when using Write-Host, the function has to write something to the pipeline Write ">" } #or if you need milliseconds Function Prompt { #[10/12/2010 8:41:47 AM]PS C:\Users\Jeff> $dt= "[{0:MM/dd/yyyy hh:mm:ss:ff}]" -f (get-date) $loc="PS {0}" -f (get-location) Write-Host $dt -NoNewline -ForegroundColor Yellow write-host $loc -NoNewline #to use Write-Host, the function has to write something to the pipeline Write ">" }