Get-QADComputer -NotLoggedOnFor 90 -SearchRoot 'doman.name/OU1/OU2'
我想为最后一个OU使用一个variablesex:
Get-QADComputer -NotLoggedOnFor 90 -SearchRoot 'doman.name/OU1/$OU2'
直接在上面的代码中出现错误“无法parsing目录对象”。 有没有办法以这种方式使用variables,或者更好的方法来做到这一点?
在Powershell中,单引号表示variables扩展不应该在string内发生。 你应该尝试用双引号"而不是:
Get-QADComputer -NotLoggedOnFor 90 -SearchRoot "doman.name/OU1/$OU2"
从文档:
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.