Posts Tagged ‘microsoft’

PowerShell: Find User Accounts Expiring in 7 days

This may help some of you; it looks for accounts within a certain OU and outputs their expiration date and email if their account expires in 7 days (no more, no less!).

# Inspired by: http://gallery.technet.microsoft.com/scriptcenter/Email-Active-Directory-452a5640
# Modified for use by; Salomon Johns
# Find users within a certain OU that have accounts expiring in 7 days (no more, no less)
# Print out the results
Get-QADUser -ou "ou=users,dc=test,dc=domain,dc=local" -includedproperties AccountExpires -sAMAccountName '*' |
ForEach-Object {
	$sevendays = (Get-Date).AddDays(7).ToString('yyyyMMdd')
	$samaccountname = $_.samAccountName
	$mail = $_.email
	$expirationdate = Get-Date $_.AccountExpires -format yyyyMMdd
	if ($expirationdate -eq $sevendays) 
		{
			Write-Host $mail,$expirationdate
		}
	}

Hope this helps out anyone that was looking for something like this. Again I only take credit for modifying it to do what I want to.

Other requirements: http://www.quest.com/powershell/activeroles-server.aspx

Further reading: If you want to change the amount of days to say 15, 21, 30, etc. All you have to do is change the following line:

From:

$sevendays = (Get-Date).AddDays(7).ToString('yyyyMMdd')

To:

$sevendays = (Get-Date).AddDays(14).ToString('yyyyMMdd')

This would in effect change it to search for accounts expiring in two weeks.

Passed the 70-642

Well, the test was actually harder than I thought, I still passed with a score in the 800′s. I will say that the book that I purchased did lack a little. The book I used as my primary study resource was MCTS Self-Paced Training Kit (Exam 70-642): Configuring Windows Server 2008 Network Infrastructure. Another friend of mine took this exam a few weeks ago, using a combination of this book and Trainsignal, he mentioned that the combination was great. On my next exam I am likely to be combining both trainsignal and the text book (70-640). I hope to have this one passed by mid-june. I will make a post regarding my thoughts on the video and textbook study method. This on top of virtual machines and hands on.