Powershell – Find the next Friday

Question:

Hoping this won’t be too difficult but I am writing a script that queries user information from the domain and exports to CSV.

The script is run by our administrative staff and all they need to input into the script is the username.

The tricky part is that I need the CSV to be named based on the coming Friday.

The way I am currently looking at going about it is as below:

This works OK with all days except Saturday.

  • If i run the day as Day 26, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 27, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 28, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 29, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 30, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 31, Month 5, Year 2013 it returns 31/05/2013
  • If i run the day as Day 1, Month 6, Year 2013 it returns 31/05/2013 (this should be 07/06/2013)
  • If i run the day as Day 2, Month 6, Year 2013 it returns 07/06/2013

What am i doing wrong?

Answer:

I’m not sure I’m following you but here’s I would get next Friday:

Source:

Powershell – Find the next Friday by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply