写一个捕获以显示不在广告中的用户名
我想编写一条线,让我知道无法找到的所有用户名,以及它们在脚本中删除的.txt文档中的显示名称。
从本质上讲,我只希望一行添加到现有脚本中。
关于如何这样做的任何提示或指导都将是很多措施。
Get-Content C:\Users\User\Desktop\findusername.txt | Foreach-Object {get-aduser -filter "displayName -like '$($_)'" | Select-Object SamAccountName} | Export-Csv -Path C:\Users\User\Documents\ADGroupusernames.csv -NoTypeInformation
I would like to write a line that lets me know any usernames that could not be found and what their display name was within the .txt document that the script is pulling from.
Essentially I just want a line to add onto the existing script.
Any tips or guidance on how to do so would be much appriciated.
Get-Content C:\Users\User\Desktop\findusername.txt | Foreach-Object {get-aduser -filter "displayName -like '$($_)'" | Select-Object SamAccountName} | Export-Csv -Path C:\Users\User\Documents\ADGroupusernames.csv -NoTypeInformation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如圣地亚哥指出的那样,当找不到匹配对象时,过滤器不会丢失错误。相反,您可以检查是否返回任何对象并对此做出反应。
As Santiago points out, filter does not throw an error when no matching objects are found. You can instead check to see if any objects are returned and react to that.