Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Is It Friday Yet?

Posted on November 5, 2009November 5, 2009

Some days the week just seems to drag on and on and on….Like many of you, I can’t wait for the end of the work day on Friday afternoon. But how much longer is it until I can say, in a cliche ridden fashion, “TGIF!” Fortunately I have PowerShell to give me a pretty accurate answer.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I wote a simple script, Get-TGIF.ps1, which lets me know how much longer I have to wait. Or if the weekend has started, that I’d better get going.

#get Friday 5:00PM for the current week

$now=Get-Date

[datetime]$TGIF="{0:MM/dd/yyyy} 5:00:00 PM" -f (($now.AddDays( 5 - [int]$now.DayOfWeek)) )

if ((get-date) -ge $TGIF) {

 write-host "TGIF has started without you!" -fore Green

 }

else {

   write-host "Countdown: $( ($tgif -(get-date)).ToString()  )" -fore magenta

 }

 #end script

The script is an example of a countdown. It gets the current date and time and saves it to $now. Then it creates a timespan object subtracting the current date and time from 5:00PM on Friday for the current week. But how do I know when that will be?

In order to properly define the $TGIF variable, I need to get the date for the next Friday. I can do this by using the integer value of the DayOfWeek property which normally just gives you the day.

PS C:\> (get-date).DayOfWeek
Thursday

However, each value has an underlying integer value.

PS C:\> (get-date).DayOfWeek -as [int]
4

Depending on your culture or regional settings you might have a different value. Usually Monday is day 1 which means Friday is 5. Therefore I simply have to subtract the current day value from 5 and then I’ll know the date of the current week’s Friday.

If the current time is greater than $TGIF then I know it’s after 5:00PM on Friday and I should be doing something else. Otherwise, the script writes a message to the host displaying the timespan object as a string.  I even created an alias, tgif, for the script so I can easily see how much longer I have.

Certainly you can change the deadline to whatever time you prefer and customize the messages.


Behind the PowerShell Pipeline
Download the script

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

4 thoughts on “Is It Friday Yet?”

  1. David R. Longnecker says:
    November 5, 2009 at 3:56 pm

    Hah! Cool and fun profile script add-on. I tossed this onto the end of my profile script so it pops out when I open up PowerShell (though, your alias idea is probably better since the console tends to be open all day).

    I did tweak the output a bit to make it more readable…

    For your “else” statement:

    else {
    $diff = $($tgif -(get-date))
    write-host “Countdown to TGIF: $($diff.Days)d $($diff.Hours)h $($diff.Minutes)m” -fore red
    }

    This outputs a bit cleaner output:

    Countdown to TGIF: 1d 1h 39m

    Example on screen: http://bit.ly/3Lg6VM

    1. Jeffery Hicks says:
      November 5, 2009 at 4:03 pm

      I like that change. The script started out “quick and dirty” and never moved much beyond it.

    2. Jeffery Hicks says:
      November 5, 2009 at 4:10 pm

      Another fun enhancement would be to use a different for the countdown method depending on how many days or hours are remaining. Maybe moving from red to green the closer you get. Heck, I might even throw in the voice object .

  2. David R. Longnecker says:
    November 6, 2009 at 8:38 am

    >>Heck, I might even throw in the voice object .

    HAH! Something that reads off the $host and if your PowerShell window is still open past closing time–“warning” you via voice API to go home. I like it! 🙂

    I’m posting up a quick post in a bit… got to thinking and since I tend to leave my PS window open all day, I added it to the window bar (or tab, since I use Console2). More on that in a few.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d