无法在 Exchange 管理控制台中将变量与 Get-User -Filter 一起使用
我似乎无法在下面的情况下使用变量。
[PS] C:\>Get-User -Filter {SamAccountName -eq "Test.Smith"}
Name RecipientType
---- -------------
Test Smith UserMailbox
[PS] C:\>$SamAccountName = "Test.Smith"
[PS] C:\>Get-User -Filter {SamAccountName -eq $SamAccountName}
[PS] C:\>echo $SamAccountName
Test.Smith
[PS] C:\>
您可以看到当我键入名称时该命令运行良好,但当我使用变量时则不然。谢谢!
I cannot seem to use variable in the situation below.
[PS] C:\>Get-User -Filter {SamAccountName -eq "Test.Smith"}
Name RecipientType
---- -------------
Test Smith UserMailbox
[PS] C:\>$SamAccountName = "Test.Smith"
[PS] C:\>Get-User -Filter {SamAccountName -eq $SamAccountName}
[PS] C:\>echo $SamAccountName
Test.Smith
[PS] C:\>
You can see the command works fine when I type out the name, but not when I use a variable. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无权访问此 cmdlet,您确定它需要脚本块而不是字符串吗?如果它需要一个字符串,请尝试以下操作:
如果它确实需要一个脚本块,请尝试:
I don't have access to this cmdlet, are you sure it takes a scriptblock and not a string? If it takes a string try this:
If it really takes a scriptblock try:
如注释中所示,请在变量周围添加单引号,否则您的过滤结果的语法不正确。
直接传递参数时,只需传递变量即可。但在本例中,您正在构建格式正确的查询字符串,单引号是其中的一部分。
当您获得完整答案时,不要将其保留为评论...将其创建为完整答案。
As seen in the comments, add single quotes around the variables, or your filter result has incorrect syntax.
When passing parameters directly you can just pass the variable. But in this case you are building a properly formatted query string, and the single quotes are part of that.
When you get a full answer, don't leave it as a comment... create it as a full answer.