Hi,
I have a powershell script for emailing a user when their AD password is due to expire. I works fine when run from the PowerGUI script editor but when I run it as an ActiveRoles scheduled task it fails.
It immediately fails by throwing "Domain 'MaximumPasswordAge' password policy is not configured."
I removed all the script logic and hard coded the $MaxPassAge to 45 then it fails to run Get-QADUser.
Its almost as if the ActiveRoles powershell modules are missing from the server but they are there and other policy scripts run fine using ActiveRoles modules.
Anyone got any ideas?
$ReqVersion = [version]"1.2.2.1254"
$QadVersion = (Get-PSSnapin Quest.ActiveRoles.ADManagement).Version
if($QadVersion -lt $ReqVersion)
{
throw "Quest AD cmdlets version '$ReqVersion' is required. Please download the latest version"
}
function Send-Mail
{
param($SmtpServer,$From,$To,$Subject,$Body)
$smtp = new-object system.net.mail.smtpClient($SmtpServer)
$mail = new-object System.Net.Mail.MailMessage
$mail.from= $From
$mail.to.add($To)
$mail.subject= $Subject
$mail.body= $Body
$smtp.send($mail)
}
$MaxPassAge = (Get-QADObject (Get-QADRootDSE).defaultNamingContextDN).MaximumPasswordAge.days
if($MaxPassAge -le 0)
{
throw "Domain 'MaximumPasswordAge' password policy is not configured."
}
$DaysToExpire = 60
$MailFrom = "helpdesk@domain.co.uk"
$PSEmailServer = "cas01"
Get-QADUser -identity "Bob.Tester" -Enabled -PasswordNeverExpires:$false -SizeLimit 0 -Email * |`
Select-Object Name,Email,@{Name="Expires";Expression={ $MaxPassAge - $_.PasswordAge.days }} |`
Where-Object {$_.Expires -gt 0 -AND $_.Expires -le $DaysToExpire } | Foreach-Object {
$Subject="Password reminder: Your password will expire in $($_.Expires) days"
if($PSVersionTable)
{
# PowerShell Version 2 detected
Send-MailMessage -From $MailFrom -To $_.Email -Subject $Subject -Body $Subject
}
else
{
# code for PowerShell v1
Send-Mail -SmtpServer $PSEmailServer -From $MailForm -To $_.Email -Subject $Subject -Body $Subject
}
}