Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
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?

share|improve this question

1 Answer 1

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 "doman.name/OU1/$OU2"

From the docs:

PS C:\> Get-Help about_Quoting
...
SINGLE AND DOUBLE-QUOTED STRINGS
    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

 
discard

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.