根据办公室位置修改用户
我无法让它发挥作用...有什么想法吗?基本上,即使用户位于芝加哥,该声明也表明该用户不在芝加哥,并且属于 else 语句。
我基本上想收集AD中的所有用户。
然后我想查看他们的办公室位置,并根据他们所在的位置,设置他们的地址......
$Users = Get-ADGroupMember "Domain Users" -recursive | Select-Object sAMAccountName
foreach ($User in $Users)
{
if
(Get-ADUser -filter {saMAccountName -eq '$User' -and Office -eq "Chicago"})
{
Set-ADUser -StreetAddress "66 Chicago Rd" -City "Chicago" -PostalCode "60618" -State "IL" -Country "US" -Replace @{ co="United States"; countryCode="804" }
}
else
{
(echo $User " not in Chicago!")}
}
I can't get this to work... any ideas? Basically, even if a user is in Chicago, the claim is the user isn't and falls in the else statement.
I basically want to collect all users in AD.
Then I want to look at their Office location and based on where they are located, set their address....
$Users = Get-ADGroupMember "Domain Users" -recursive | Select-Object sAMAccountName
foreach ($User in $Users)
{
if
(Get-ADUser -filter {saMAccountName -eq '$User' -and Office -eq "Chicago"})
{
Set-ADUser -StreetAddress "66 Chicago Rd" -City "Chicago" -PostalCode "60618" -State "IL" -Country "US" -Replace @{ co="United States"; countryCode="804" }
}
else
{
(echo $User " not in Chicago!")}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能试试这个吗:
我只是替换
为
Can you try this :
I just replace
by
试试这个,由于某种原因 $obj.Property 没有在过滤器脚本块中扩展。我使用 Foreach-Object 而不是 Select-Object 来提取 sAMAccountName 的值。您还缺少在 Set-ADUser 命令中设置的用户对象:
更新:
您还可以通过以下一行使用相关 cmdlet 的流式传输性质(一次处理一个对象):
Try this, for some reason $obj.Property is not expanded in the filter scriptblock. I used Foreach-Object instead of Select-Object to extract the values of sAMAccountName. You were also missing the user object to set in the Set-ADUser command:
UPDATE:
You can also use the streaming nature of the cmdlets in question (process one object at a time) with the following one-liner: