header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Powershell Variable in LDAP Filter
Last Post 02 Jul 2010 08:47 AM by PoSherLife. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
Ryan BachmanUser is Offline
New Member
New Member
Posts:8
Avatar

--
01 Jul 2010 12:48 PM
    Hello all -

    Need to know if there is a way to define a varible based on date, and then query an AD Ldap field based on that variable.  Bellow is rudimentary code of what I am trying to do, just not sure if I can use the defined vairbale in my search string.  Tried this but it appears it is returning results based on the literal text, and not the varibale value. 
    [string] $a=get-date -uformat %m%y [string] $revoke = $a - 200 dsquery * forestroot -filter "&(objectClass=User)(description=*$revoke*)" -limit 0 -attr sAMAccountName -l

    Thanks for the help!

    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    02 Jul 2010 06:53 AM
    lets start by fixing one piece of code and getting rid of $a:
    $revoke = Get-Date -UFormat %m%y ((get-date).AddMonths(-2))

    You may need $() around $revoke in your command:
    dsquery * forestroot -filter "&(objectClass=User)(description=*$($revoke)*)" -limit 0 -attr sAMAccountName -l
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    Ryan BachmanUser is Offline
    New Member
    New Member
    Posts:8
    Avatar

    --
    02 Jul 2010 07:52 AM

    That did the trick.  Thanks for the .addMonths function as well. 

    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    02 Jul 2010 08:47 AM
    The $ tells powershell to execute the expression contained within the proceeding parenthesis. Therefore, this could be done as a oneliner, but makes it a bit long:

    dsquery * forestroot -filter "&(objectClass=User)(description=*$(Get-Date -UFormat %m%y ((get-date).AddMonths(-2)))*)" -limit 0 -attr sAMAccountName -l

    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer