get last workday

Welcome Forums General PowerShell Q&A get last workday

Viewing 2 reply threads
  • Author
    Posts
    • #230584
      Participant
      Topics: 34
      Replies: 82
      Points: 467
      Rank: Contributor

      Hi,
      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.

    • #230617
      Participant
      Topics: 6
      Replies: 20
      Points: 68
      Helping Hand
      Rank: Member

      Hi,

      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…

    • #230656
      Participant
      Topics: 34
      Replies: 82
      Points: 467
      Rank: Contributor

      Gnart thanks
      that’s exactly what I needed

      Best regards

      Paul

       

Viewing 2 reply threads
  • You must be logged in to reply to this topic.