Trying to understand what is going on in this bit of code.

Welcome Forums General PowerShell Q&A Trying to understand what is going on in this bit of code.

Viewing 2 reply threads
  • Author
    Posts
    • #272260
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Thank you for taking a look.

      I have a script that grabs disabled AD users and sorts them by last logon date. The output is an HTML table. That works fine. I have an additional script i found that will color a cell or row based on a filter and it works as long as I am not using dates. Looking into it more that script is okay but PS is doing something odd. Please look at the code below. I’d like to know why dates with the months January and October create a false condition.

      Thank you for your help,

      Paul

      • This topic was modified 2 weeks, 1 day ago by kvprasoon. Reason: Code formatting
    • #272398
      Participant
      Topics: 17
      Replies: 1869
      Points: 3,631
      Helping Hand
      Rank: Community Hero

      Wrapping a date in qoutes is not automatically parsed to datetime type, you need to parse it to a date:

      Recommend wrapping the parse in parenthesis to ensure that it is parsed before the comparison:

      Another option is to use New-TimeSpan to get the number of days versus just doing a basic boolean check.

      • This reply was modified 2 weeks, 1 day ago by Rob Simmers.
    • #272470
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Thank you Rob, I thought I was going crazy. Much appreciate.

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