[英]Get groups from user list?
I need to get groups for list of users. 我需要为用户列表获取组。 I can do that for users in TST1.txt list using below PS command:
我可以使用以下PS命令为TST1.txt列表中的用户执行此操作:
Get-Content D:\TST1.txt | Get-ADPrincipalGroupMembership |
select name | Out-File -Append D:\TST2.txt
But that list don't have user name and bit messy. 但是该列表没有用户名,而且有点混乱。 below won't work either.
下面的方法也不起作用。
Get-Content D:\TST1.txt | Get-ADUser | select name |
Get-ADPrincipalGroupMembership | select name |
Out-File -Append D:\TST2.txt
Use ForEach-Object
, store the username in a variable and use that with Select-Object
to create a calculated property: 使用
ForEach-Object
,将用户名存储在变量中,然后将其与Select-Object
一起使用以创建计算所得的属性:
Get-Content D:\TST1.txt | ForEach-Object {
$Username = $_
Get-ADPrincipalGroupMembership -Identity $UserName |Select-Object @{Name='Username';Expression={$Username}},Name
} |Out-File -Append D:\TST2.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.