get-date error

Hi, the below script runs properly, I am able to return results of the SamAccountName as well as password expiration date. However, I get this error, and scratching my head on how to resolve.

get-date : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At C:\Users\a_dtuan\Scripts\testpwdexpiration.ps1:7 char:19

  • ($_.ExpiryDate | get-date) -gt (get-date) -and ($_.ExpiryDate | g ...
    
  •                  ~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-Date], ParameterBindingException

Get-ADUser -filter * -SearchBase "OU=Users,DC=XX,DC=XX,DC=XX" -properties SamAccountName,PasswordNeverExpires,msDS-UserPasswordExpiryTimeComputed |
where {
$
.enabled -eq $true -and $.PasswordNeverExpires -eq $False
} |
select @{Name=“ID”;Expression={$
.sAMAccountName}},@{Name=“ExpiryDate”;Expression={([datetime]::FromFileTime($.“msDS-UserPasswordExpiryTimeComputed”)).DateTime}} |
where {
($
.ExpiryDate | get-date) -gt (get-date) -and ($_.ExpiryDate | get-date) -lt (get-date).adddays(7)} |
Export-Csv C:\temp\PwdExpiration\pwdexpiration.csv -notypeinformation

You need to use -as [DateTime] instead of trying to pipe to Get-Date cmdlet as in:

Get-ADUser -Filter * -properties SamAccountName,PasswordNeverExpires,msDS-UserPasswordExpiryTimeComputed |
    where { $_.enabled -eq $true -and $_.PasswordNeverExpires -eq $False } |
        select  @{Name=”ID”;Expression={$_.sAMAccountName}},
                @{Name=”ExpiryDate”;Expression={([datetime]::FromFileTime($_.”msDS-UserPasswordExpiryTimeComputed”)).DateTime}} | 
            where { ($_.ExpiryDate -as [DateTime]) -gt (get-date) -and ($_.ExpiryDate -as [DateTime]) -lt (get-date).adddays(7) } |
                Export-Csv C:\temp\PwdExpiration\pwdexpiration.csv -notypeinformation

Thanks Sam, that worked like a charm.