Parsing date from CSV

Welcome Forums General PowerShell Q&A Parsing date from CSV

Viewing 3 reply threads
  • Author
    Posts
    • #256676
      Participant
      Topics: 8
      Replies: 12
      Points: 168
      Rank: Participant

      Good morning my fine powershell friends!  I have a csv that I am using for a new-aduser creation.  One of my headers is called Wdate, which holds a date that a user should be expired.  I need to add 30 days to it then it will become disabled and moved to a specific OU.  I have been reading about parseExact, and although I understand what it does I am not quite sure how to implement it within the script.  Any help is greatly appreciated.  Below is an example of the csv, and the script I am testing on my test lab.

      SamAccountName LastName FirstName Middle Pin Adult Wdate Status
      N417934 Abbott Breanna K 1234 A 2020-07-02 W
      S39306650 Anderson Ken G 1234 2020-08-14 W
      • This topic was modified 1 week, 1 day ago by Richard. Reason: Code format didn't work
      • This topic was modified 1 week, 1 day ago by grokkit. Reason: please read the guide: https://powershell.org/forums/topic/guide-to-posting-code-2/
    • #256730
      Participant
      Topics: 8
      Replies: 565
      Points: 2,158
      Helping Hand
      Rank: Community Hero

      The parseexact() method allows you to specify what format the date is in. You are very close. Simply change it to

      If the date looked like 20200702 then you would’ve had the correct format.

    • #256745
      Participant
      Topics: 8
      Replies: 12
      Points: 168
      Rank: Participant

      Ok I was close….thank you for the reply. I am still unsure on how to define that variable. Do I still do a $Disable = $User.Wdate? Further in the script I need to add 30 days to the date in the csv and as of right now that isn’t working. Is there another way I need to define this variable to use it in the script?

    • #256784
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,783
      Helping Hand
      Rank: Community Hero

      Once you have an object of [DateTime] type, then you can use AddDays() method to add days.

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