Get-QADComputer -NotLoggedOnFor 90 -SearchRoot 'doman.name/OU1/OU2'

I would like to use a variable for the last OU ex:

Get-QADComputer -NotLoggedOnFor 90 -SearchRoot 'doman.name/OU1/$OU2'

I get an error "cannot resolve directory object" for the code directly above. Is there a way to use a variable in this manner or an outright better way to do this?


In Powershell, single quotes ' indicates variable expansion should not happen within the string. You should try with the double quotes " instead:

Get-QADComputer -NotLoggedOnFor 90 -SearchRoot "doman.name/OU1/$OU2"

From the docs:

PS C:\> Get-Help about_Quoting
    When you enclose a string in double quotation marks (a double-quoted
    string), variable names that are preceded by a dollar sign ($) are
    replaced with the variable's value before the string is passed to the
    command for processing.
    When you enclose a string in single-quotation marks (a single-quoted
    string), the string is passed to the command exactly as you type it.
    No substitution is performed.
  • Thanks. I tried putting the actually variable in "" but not the whole string. – user179037 Sep 27 '13 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.