Help Regarding compairing dates from two columns in CSV

Hello Everyone,

I am trying to compare terminated users dates from CSV against AD(In AD we use a powershell script that we run for terminating a user that sets date/time of user’s termination in user’s description field). I am thinking of

  1. Importing users from CSV (that has list of terminated users and date/times of terminations generated in another system) based on username and get description field from AD that contains date/time of terminations and compare both times to find out any delays. I have small code that I started with
$testcsv = import-csv C:\users\username\documents\test.csv

ForEach ($user in $testcsv)

$username = $user.username
Get-ADUser -Filter {samaccountname -eq $username} -Properties * |
Select-Object description | Export-csv C:\users\username\documents\new.csv -append


Any Ideas on how to achieve this or plan this because I am new to PowerShell. Any guidance will be appreciated.

Thank You



Your post is only selecting users, you are not selecting any date info relative to the user or what’s in the CSV. Thus you can compare anything that you have not asked code. You don’t show any part of the CSV, so we see what the date string / format looks like.

You say …

Any Ideas on how to achieve this or plan this because I am new to PowerShell.
… that's all well and good, as we all had to start form somewhere, but, you should really spend the needed time getting up to speed on it, to limit / eliminate, confusions, frustration, unnecessary errors, bad habits, poor code, and hurting your system or your environment.

See these resources below and the Free eBooks / videos on this site you asked this on. Use the ‘Free Resources’ like in the side menu section and the search bar to see other posts that could be close to what you are asking for.

You are just doing a read here, so, no real damage can be done, but just saying, as you go down this path, don’t guess, read the help files, view the videos on YouTube and MSDN Channel9 on PowerShell and ADDS, files, folders, loops, compare, etc. Just search for them.

Your query is really a PowerShell with ADDS 101 thing. Something easily found using your favorite search engine. Looking for stuff like ‘PowerShell working with csv’, ‘PowerShell date compare’, ‘PowerShell compare csv dates to active directory dates’, etc. Thus getting back stuff like this…

Compare AD against CSV -

PowerShell Dates - PowerShell Dates


Learning this stuff.

Best Practices


Practice with PSKoans

PSKoans : 0.50.0
A module designed to provide a crash-course introduction to PowerShell with programming koans.

Book references, normally the ones you’ll see most recommend:

Beginning —

Learn Windows PowerShell in a Month of Lunches 3rd Edition
Donald W. Jones (Author),‎ Jeffrey Hicks (Author)
ISBN-13: 978-1617294167
ISBN-10: 1617294160

Intermediate —

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft’s Command Shell 3rd Edition
Lee Holmes (Author)
ISBN-13: 978-1449320683
ISBN-10: 1449320686

Advanced —

Windows PowerShell in Action 3rd Edition
by Bruce Payette (Author),‎ Richard Siddaway (Author)
ISBN-13: 978-1633430297
ISBN-10: 1633430294

From Microsoft

Windows PowerShell Survival Guide


Lastly, never ever, run any code from any one from anywhere, that you do not fully understand and what it is / will do. If you do, you could seriously damage your host and or your enterprise. Learn to master the -WhatIf, -Confirm, and leveraging the Set-StrictMode are part of your development, put that in your profile. Learn about profiles, and how to use them. Learn about execution policies, what they are and how / when to use them. Fully leverage auditing, monitoring and logging of PowerShell use by all users and processes. Especially as part of your corporate risk management effort.





Thank You