How to Get options for -filter command in Get-adComputer

Welcome Forums General PowerShell Q&A How to Get options for -filter command in Get-adComputer

Viewing 1 reply thread
  • Author
    Posts
    • #255509
      Participant
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      Hi,

       

      I know this is a noob question. I understand the -filter param on the “get-adcomputer” command is filtering most likely by using an object value(or ldap value); however I cant seem to find out how i would find out those values are (the possible options for filter param)

       

      I could open the psm and look inside identifying the code; however I must be missing some basics here. 🙂

       

      If I assign get-adcomputer to a var and then output the var to select-object *; I don’t get a value that represents (as an example) “Get-AdComputer -filter {OperatingSystem -like “Windows Server”}”

       

       

      Tried; (with no luck)

      get-command -Name Get-adComputer | Select-Object *

      get-member -inputobject Get-ADComputer -MemberType All

       

      Thank you,

      jajabinks

      • This topic was modified 2 weeks, 2 days ago by jajabinks78.
    • #255521
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      The filter value is a string in the form propertyName -operator propertyValue. However, how the string and values are quoted do matter. You should never use the script block notation { property -operator value }despite what the documentation shows because it is incorrect. The reason quoting gets wonky is because the local PowerShell shell can interpolate strings and the called Get-AdComputer can expand strings. Here are some acceptable examples:

      The outer quotes are handled by the local PowerShell parser. The inner value is passed to the command for further parsing. Any variable inside of a outer double quotes is expanded inside. So if you want the command to interpret the variable instead of the calling PowerShell parser, you must use single quotes. Basically, if you want the command to determine the variable value, then use outer single quotes and nothing inside. If you want the calling shell to interpret first, then use outer double quotes. But since the inside value will be expanded before being sent to the command, you must give the value inner single quotes so the command will know it is a string.

      Due to how $object.property syntax is handled within strings, you must surround the reference in the sub-expression operator $() . Otherwise, only the variable $object gets interpolated and then .property is literally just appended to the end of the result. Since you want PowerShell to parse that sub-expression for you, you can use outer double quotes and inner single quotes.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.