Hey Olaf,
Hope you are doing great !
Thank you for looking into this.
Sorry I didn’t know how to use the </> button. Trying it once again now.
The complete code is here:
##################################################
# Configurable Variables
$smtpServer="SMTPSERVERNAME"
$expireindays = 14
$from = "USERID"
$date = Get-Date -format ddMMyyyy
$link1 = "URL1"
$link2 = "URL2"
#
###################################################################################################################
# Get Users From AD who are Enabled, Passwords Expire and are Not Currently Expired
Import-Module ActiveDirectory
$users = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} -SearchBase 'DNOUPATH' –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |
Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
# Process Each User for Password Expiry
foreach ($user in $users)
{
$Name = (Get-ADUser $user | foreach { $_.Name})
$emailaddress = $user.emailaddress
$passwordSetDate = (get-aduser $user -properties * | foreach { $_.PasswordLastSet })
$PasswordPol = (Get-AduserResultantPasswordPolicy $user)
# Check for Fine Grained Password
if (($PasswordPol) -ne $null)
{
$maxPasswordAge = ($PasswordPol).MaxPasswordAge
}
$expireson = $passwordsetdate + $maxPasswordAge
$today = (get-date)
$daystoexpire = (New-TimeSpan -Start $today -End $Expireson).Days
# Set Greeting based on Number of Days to Expiry.
# Check Number of Days to Expiry
$messageDays = $daystoexpire
if (($messageDays) -ge "1")
{
$messageDays = "in " + "$daystoexpire" + " days"
}
else
{
$messageDays = "today."
}
# Email Subject Set Here
$subject="EMAILSUBJECT $messageDays"
# Email Body Set Here
$body ="
Dear $name,
<p> Your password will expire on $ExpiresOn. It's time to reset the Password. <br>
<p> To reset your password from your Industry computer, press Ctrl+Alt+Delete and choose Change Password. <br>
<b><font color=red>Please note that replies to this email will not be answered</font></b>
<p><br>Have a great day, <br>
</P>DL@COMPANY.COM"
# If a user has no email address listed
if (($emailaddress) -eq $null)
{
$emailaddress = $testRecipient
}# End No Valid Email
# Send Email Message
if (($daystoexpire -ge "0") -and ($daystoexpire -lt $expireindays))
{
# Send Email Message
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High
} # End Send Message
} # End User Processing
# End
#######################################################
The error messages is here (sorry its too lengthy):
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:22 char:25
+ $Name = (Get-ADUser $user | foreach { $_.Name})
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:24 char:36
+ $passwordSetDate = (get-aduser $user -properties * | foreach { $_ ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-AduserResultantPasswordPolicy : Object reference not set to an instance of an object.
At line:25 char:21
+ $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...nagement.ADUser:ADUser) [Get-ADUserResultantPasswordPolicy], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUserResultantPasswordPolicy