简体   繁体   English

从文本文件中提取每个用户的“成员”安全组列表

[英]Pull each user's "Member Of" security group list from a text file

I written the below PowerShell script to pull the list security for each user.我编写了以下 PowerShell 脚本来为每个用户拉取列表安全性。 All user list are inside the text file "ulist.txt" line by line.所有用户列表都在文本文件“ulist.txt”中逐行显示。 It not pull some user from that text file where as that really exist inside the directory.它不会从该文本文件中提取某些用户,因为它确实存在于目录中。

Clear-Host
$ul = Get-Content -Path "C:\Users\username\Desktop\ulist.txt"

ForEach ($item in $ul){
$item = $item.toupper()
Write-Host ------------------------------------------------------------------ -ForegroundColor Yellow
Write-Host The user $item belongs to following security groups. -ForegroundColor Yellow
Write-Host ------------------------------------------------------------------ -ForegroundColor Yellow
$allgroups = Get-ADUser $item -Properties *  | Get-ADPrincipalGroupMembership | Select-Object name | Format-Table -HideTableHeaders | Out-String | ForEach-Object { $_.Trim("`r","`n") } 
$allgroups
Write-Host ------------------------------------------------------------------ -ForegroundColor Yellow 
}

Error:错误:

Get-ADUser : Cannot find an object with identity: xxxxxxxx
Get-ADUser : Cannot validate argument on parameter 'Identity'. 
             The Identity property on the argument is null or empty.

I do not understand what is wrong in this script.我不明白这个脚本有什么问题。

It only pull and showing only the default group "Domain Users" for some users not the other groups associated.它只为某些用户拉取并显示默认组“Domain Users”,而不是其他相关组。

After modified a little bit when it was pulled and appended the user list, I did a little bit mistake.在拉取并附加用户列表时稍作修改后,我犯了一点错误。 Instead of "select Name", I changed it to "select SamAccountName".我将其改为“选择 SamAccountName”,而不是“选择名称”。 Perfect, it displayed me what I was expecting.完美,它向我展示了我的期望。

Thank you Team.谢谢团队。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于在所有文件夹上拉取 ACL for.network drive 和列表文件路径、安全组、安全组中的用户的脚本 - Script to pull ACL on all folders for network drive and list File path, Security Group, users in the security group 将用户的组成员身份导出到文本文件 - Export user's group memberships to a text file 如果用户不是某个安全组的成员,如何从 Teams 共享频道中删除用户? - How do I remove a User from a Teams Shared Channel if they are not a member of a certain security group? Powershell-文本文件中的用户组成员身份 - Powershell - User group membership from text file 如果用户是组列表的成员,如何遍历用户的组成员资格并返回用户 - How to iterate through user's group membership and return user if they are a member of a list of groups 使用 CSV 文件中的用户列表更新安全组 - Updating a security group with a list of users from a CSV file 阵列中每个用户的Powershell列表组名称 - Powershell list group names for each user in array 将 DisplayName 列表中的用户添加到安全组 - Add users from DisplayName list to security group 从employeeID的列表中将SamAccountName拉入csv - Pull SamAccountName into csv from list of employeeID's 在 CSV 文件中列出是否启用或禁用 AD 组成员 - List if AD group member is enabled or disabled in CSV file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM