get-date error

Welcome Forums General PowerShell Q&A get-date error

Viewing 2 reply threads
  • Author
    Posts
    • #211101
      Participant
      Topics: 1
      Replies: 1
      Points: -7
      Rank: Member

      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: (:) [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

    • #211104
      Participant
      Topics: 12
      Replies: 523
      Points: 1,214
      Helping Hand
      Rank: Community Hero

      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
      
      • This reply was modified 2 months, 2 weeks ago by Sam Boutros.
    • #211122
      Participant
      Topics: 1
      Replies: 1
      Points: -7
      Rank: Member

      Thanks Sam, that worked like a charm.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.