简体   繁体   English

将变量与 Get-ADUser -Filter * -SearchBase 一起使用

[英]Using variable with Get-ADUser -Filter * -SearchBase

I am trying to use a loop in我正在尝试使用循环

Get-ADUser -Filter * -SearchBase $variable获取 ADUser -Filter * -SearchBase $variable

to get all the users from different OU, but its not working.从不同的OU获取所有用户,但它不起作用。

Here is my code:这是我的代码:

$myArray = 'IT', 'HR', 'IMMO'

foreach ($i in $myArray) {
    Get-ADUser -Filter * -SearchBase "OU=""$i"",DC=MyLAB,DC=local" -Properties Name, mail, telephoneNumber | Where-Object {$_.mail -ne $null} | Where-Object {$_.telephoneNumber -ne $null} }

Removing the quotes around $i should work... Like this;删除 $i 周围的引号应该可以工作......就像这样;

$myArray = 'IT', 'HR', 'IMMO'

foreach ($i in $myArray) {
    Get-ADUser -Filter * -SearchBase "OU=$i,DC=MyLAB,DC=local" -Properties Name, mail, telephoneNumber | Where-Object {$_.mail -ne $null} | Where-Object {$_.telephoneNumber -ne $null} }

What if you remove all the other stuff for now, can you get this bit to work?如果你现在删除所有其他的东西,你能让这部分工作吗?

$myArray = 'IT', 'HR', 'IMMO'
foreach($i in $myArray)
{
    Get-ADUser -Filter * -SearchBase "OU=$i,DC=MyLAB,DC=local"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM