在GET-ADUser便有Powershell的变量 [英] Powershell variables in Get-AdUser

查看:565
本文介绍了在GET-ADUser便有Powershell的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写一个简单的PowerShell脚本。

I'm trying to write a simple powershell script.

Get-ADuser -Filter {GivenName -eq $GivenName $hateList} -SearchBase $Container -Properties displayName,telephoneNumber,department|ForEach-Object {"FullName`t: $($_.displayName)`r`nPhone`t`t: $($_.telephoneNumber)`r`nDepartment`t: $($_.department)`r`n"}

错误我得到了什么:     获取-ADUser便有:错误分析查询:GivenName上当量$ GivenName上$ hateList错误信息:语法错误的位置:26

The error what I got: Get-ADUser : Error parsing query: 'GivenName -eq $GivenName $hateList' Error Message: 'syntax error' at position: '26'.

所以问题是,变量不取代的它们的值。我该怎么办错了?

So the problem is that the variables aren't substituted with their values. What do I do wrong?

推荐答案

您筛选参数是不正确的。如果你想有GivenName上等于$ GivenName上,你应该做的是这样的:

You Filter parameter is not right. If you want to have GivenName be equal to $GivenName you should do it like this:

{GivenName -eq $GivenName}

如果你想让它等于$ GivenName上或$ hateList,不管它是什么,你应该尝试是这样的:

If you want it to be equal to $GivenName or $hateList, whatever it is, you should try something like:

{(GivenName -eq $GivenName) -or (GivenName -eq $hateList)}

检查该链接查看更多过滤: http://technet.microsoft.com/en-us/library/ee617241.aspx

Check this link for more filter: http://technet.microsoft.com/en-us/library/ee617241.aspx

您可以先获取用户列表,像这样的过滤器:

You can first get list of users with filter like this:

{GivenName -eq $GivenName}

而做一些后期处理:

And the do some post processing:

$users | Where-Object { $hateList -notcontains  $_.cn }

这篇关于在GET-ADUser便有Powershell的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆