get last workday

current situation
lastworking day from a given user is thursday and the account will be disabled on friday. with these 2 lines of code I can correctly build up the description field mentioning account disabled on $date and last working day is $lastworkday
$date= Get-Date -Format “yyyy-MMM-dd”
$lastworkdate = (get-date).AddDays(-1).ToString(“yyyy-MMM-dd”)

However I’ve got to take into consideration that

  1. that user has a last working day on friday and when I run my script on my next working day which is monday my counter should say account disabled on Monday last working day on Friday
  2. in addition accounts may be disabled by someone in Israel (where their weekend is Friday saterday) so when this person does disable the account on Sunday the last workingday should be Friday as well

any Idea’s on how to incorporate this.


For #1, you could check for the day of week on which you ran the code, ie.
if ((get-date).DayOfWeek -like ‘Monday’) { write-host ‘Account disabled on Monday, lastworking day on Friday - processing logic’}

For #2, it depends whether the host (where PS is run) timezone / local region are set properly. You could check by using PS Get-TimeZone, Get-WinHomeLocation, Get-WinSystemLocale…

Hope the above get you going in the right direction…

Gnart thanks
that’s exactly what I needed

Best regards