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?

jscott
  • 24,204
  • 8
  • 77
  • 99
user179037
  • 77
  • 1
  • 3
  • 6

1 Answers1

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.
jscott
  • 24,204
  • 8
  • 77
  • 99