Get-ADUser 中带有变量的通配符 [英] Wildcard with variable in Get-ADUser

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

问题描述

我确定这只是一个语法错误,但我正在尝试搜索 AD 用户,但我无法弄清楚为什么这不起作用:

Im sure this is just a syntax error, but im trying to search AD users, and I cannot figure out why this does not work:

Write-Host "Enter LastName or UserName:"
$x = Read-Host
Get-ADUser -Filter { SAMAccountName -like '*$x*' } -Properties DispalyName | FT -Properties DisplayName

只是不返回任何东西.而且我确定它是带有*"的语法.但不知道为什么.感谢您的帮助.

Just doesnt return anything. And im sure it is syntax with the "*". but not sure why. Thanks for any help.

推荐答案

$x 未在 Filter 脚本块内展开,这应该可以解决问题:

$x is not expanded inside the Filter scriptblock, this should do the job:

$x = 'mini'
Get-ADUser -Filter "SamAccountName -like '*$x*'" -Properties DisplayName | ft DisplayName 

DisplayName
-----------
Administrator

或者,您可以使用 ldap 过滤器:

Alternatively, you could use ldap filter:

Get-ADUser -LDAPFilter "(samaccountname=*$x*)"

这篇关于Get-ADUser 中带有变量的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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