ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell: I got something wrong.

    IT Discussion
    powershell
    4
    17
    1.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EddieJenningsE
      EddieJennings @Grey
      last edited by

      @grey said in Powershell: I got something wrong.:

      Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and -lt "8/21/2017") -and enabled -eq $true} -Properties PasswordLastSet,Name,Description
      

      Ok, this line isn't working to find the users that changed their password between the 16th and the 21st. Where did I go wrong?

      Are you receiving an error message or incorrect results?

      GreyG 1 Reply Last reply Reply Quote 0
      • DashrenderD
        Dashrender
        last edited by

        It fails for me on the use of PassWordNeverExpires

        help does show that option for Get-AdUser

        PS C:\WINDOWS\system32> help passwordneverexpires
        
        Name                              Category  Module                    Synopsis
        ----                              --------  ------                    --------
        Get-ADComputer                    Cmdlet    ActiveDirectory           Gets one or more Active Directory computers.
        New-ADComputer                    Cmdlet    ActiveDirectory           Creates a new Active Directory computer.
        New-ADUser                        Cmdlet    ActiveDirectory           Creates a new Active Directory user.
        Search-ADAccount                  Cmdlet    ActiveDirectory           Gets Active Directory user, computer, or servi...
        Set-ADAccountControl              Cmdlet    ActiveDirectory           Modifies user account control (UAC) values for...
        Set-ADComputer                    Cmdlet    ActiveDirectory           Modifies an Active Directory computer object.
        Set-ADUser                        Cmdlet    ActiveDirectory           Modifies an Active Directory user.
        
        1 Reply Last reply Reply Quote 1
        • GreyG
          Grey @EddieJennings
          last edited by

          @eddiejennings Shown:

          PS Z:\Scripts> Get-ADUser -filter {PasswordNeverExpires -eq $false -and PasswordLastSet -gt "8/16/2017" -and -lt "8/21/2017" -and enabled -eq $true} -Properties PasswordLastSet,Name,DistinguishedName 
          
          Get-ADUser : Error parsing query: 'PasswordNeverExpires -eq $false -and PasswordLastSet -gt "8/16/2017" -and -lt "8/21/2017" -and enabled -eq $true' Error Message: 'syntax error' at position: '75'.
          At line:1 char:1
          + Get-ADUser -filter {PasswordNeverExpires -eq $false -and PasswordLast ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : ParserError: (:) [Get-ADUser], ADFilterParsingException
              + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
           
          
          PS Z:\Scripts> Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and -lt "8/21/2017") -and enabled -eq $true} -Properties PasswordLastSet,Name,DistinguishedName 
          
          Get-ADUser : Error parsing query: 'PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and -lt "8/21/2017") -and enabled -eq $true' Error Message: 'syntax error' at position: '76'.
          At line:1 char:1
          + Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLas ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : ParserError: (:) [Get-ADUser], ADFilterParsingException
              + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
          

          It worked prior to adding the -gt/-lt params, or with just one of those params.

          1 Reply Last reply Reply Quote 0
          • EddieJenningsE
            EddieJennings
            last edited by

            I think Dash is on the right trail. Try it without the PasswordNeverExpires parameter.

            GreyG 1 Reply Last reply Reply Quote 1
            • DashrenderD
              Dashrender
              last edited by Dashrender

              OK

              Get-ADUser -filter {PasswordNeverExpires -eq $false}
              

              and

              Get-ADUser -filter {PasswordNeverExpires -eq $false} -Properties PasswordLastSet,Name,Description
              

              do work. Though I'm guessing that the -Properties option is meant to limit the output to only those three things, which it does not do, but I could be wrong on the expectation.
              In either case, the output from both commands is the same.

              1 Reply Last reply Reply Quote 0
              • GreyG
                Grey @EddieJennings
                last edited by

                @eddiejennings said in Powershell: I got something wrong.:

                I think Dash is on the right trail. Try it without the PasswordNeverExpires parameter.

                That param is fine. The dates are what's generating the error as it's not able to figure out both lt and gt, I think?

                DashrenderD JaredBuschJ 2 Replies Last reply Reply Quote 0
                • DashrenderD
                  Dashrender @Grey
                  last edited by

                  @grey said in Powershell: I got something wrong.:

                  @eddiejennings said in Powershell: I got something wrong.:

                  I think Dash is on the right trail. Try it without the PasswordNeverExpires parameter.

                  That param is fine. The dates are what's generating the error as it's not able to figure out both lt and gt, I think?

                  yeah, when I only put that one filter in place, it's failing for me, the rest work.

                  1 Reply Last reply Reply Quote 0
                  • JaredBuschJ
                    JaredBusch @Grey
                    last edited by

                    @grey Specify PasswordLastSet after the -and also otherwise it has no idea what you are trying to -lt.

                    Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and PasswordLastSet -lt "8/21/2017") -and enabled -eq $true} -Properties PasswordLastSet,Name,Description
                    
                    GreyG 1 Reply Last reply Reply Quote 2
                    • DashrenderD
                      Dashrender
                      last edited by

                      damn - JB beat me by a few seconds

                      1 Reply Last reply Reply Quote 0
                      • EddieJenningsE
                        EddieJennings
                        last edited by

                        I should only respond to posts when I can give them due attention. I feel like a fool for missing that. 😕

                        1 Reply Last reply Reply Quote 0
                        • DashrenderD
                          Dashrender
                          last edited by

                          I wonder if you can drop the and, and give the -gt -lt commands to the single commandlet?

                          JaredBuschJ 1 Reply Last reply Reply Quote 0
                          • JaredBuschJ
                            JaredBusch @Dashrender
                            last edited by

                            @dashrender said in Powershell: I got something wrong.:

                            I wonder if you can drop the and, and give the -gt -lt commands to the single commandlet?

                            not how that works.

                            DashrenderD 1 Reply Last reply Reply Quote 0
                            • DashrenderD
                              Dashrender @JaredBusch
                              last edited by

                              @jaredbusch said in Powershell: I got something wrong.:

                              @dashrender said in Powershell: I got something wrong.:

                              I wonder if you can drop the and, and give the -gt -lt commands to the single commandlet?

                              not how that works.

                              Yeah I just tried, and nope failed.

                              JaredBuschJ 1 Reply Last reply Reply Quote 0
                              • JaredBuschJ
                                JaredBusch @Dashrender
                                last edited by JaredBusch

                                @dashrender said in Powershell: I got something wrong.:

                                @jaredbusch said in Powershell: I got something wrong.:

                                @dashrender said in Powershell: I got something wrong.:

                                I wonder if you can drop the and, and give the -gt -lt commands to the single commandlet?

                                not how that works.

                                Yeah I just tried, and nope failed.

                                There is no -between functionality in powershell.

                                1 Reply Last reply Reply Quote 0
                                • GreyG
                                  Grey @JaredBusch
                                  last edited by

                                  @jaredbusch said in Powershell: I got something wrong.:

                                  @grey Specify PasswordLastSet after the -and also otherwise it has no idea what you are trying to -lt.

                                  Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and PasswordLastSet -lt "8/21/2017") -and enabled -eq $true} -Properties PasswordLastSet,Name,Description
                                  

                                  You win at the Internet today. I should have caught that.

                                  JaredBuschJ 1 Reply Last reply Reply Quote 0
                                  • JaredBuschJ
                                    JaredBusch @Grey
                                    last edited by

                                    @grey said in Powershell: I got something wrong.:

                                    @jaredbusch said in Powershell: I got something wrong.:

                                    @grey Specify PasswordLastSet after the -and also otherwise it has no idea what you are trying to -lt.

                                    Get-ADUser -filter {PasswordNeverExpires -eq $false -and (PasswordLastSet -gt "8/16/2017" -and PasswordLastSet -lt "8/21/2017") -and enabled -eq $true} -Properties PasswordLastSet,Name,Description
                                    

                                    You win at the Internet today. I should have caught that.

                                    I did enough time in development. I know how it goes.

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post