3
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?

1 Answer 1

5

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.
1
  • Thanks. I tried putting the actually variable in "" but not the whole string.
    – user179037
    Sep 27, 2013 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .