Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
Get-QADComputer -NotLoggedOnFor 90 -SearchRoot ''

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

Get-QADComputer -NotLoggedOnFor 90 -SearchRoot '$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?

share|improve this question
up vote 5 down vote accepted

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 "$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.
share|improve this answer
Thanks. I tried putting the actually variable in "" but not the whole string. – user179037 Sep 27 '13 at 16:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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