将组名行添加到组成员输出

时间:2016-04-18 12:58:59

标签: powershell

我正在尝试将一些群组成员资格全部导出到一个CSV文件,以便找到不在我们域中的用户。一切都很好,但是当所有输出都被追加时,我看不出每个条目所属的组。这就是我现在所拥有的。

@something().where("Year.name = 2003").where("Month.name = May").where("Day.name = 12")

如何在追加组名称之间添加一行,可能来自导入?

谢谢!

1 个答案:

答案 0 :(得分:0)

我过去做过类似的事情。希望这段代码有所帮助:

Function ADGroupMembers
{
$group = get-content C:\Pshell\PM\group.txt 
$i =25

do{
if (get-QADgroup $group[$i] -Empty 0) 
    {write-output ''; Write-Output -inputobject "The $($group[$i]) group members :"; write-output ''; 
 get-QADGroupMember $group[$i] -IncludeAllProperties | Format-Table -AutoSize DisplayName, Type, Office, Company, Department, Title, WhenCreated  | Out-String -Width 4096; 
 write-output ''} 

else {Write-Output -inputobject "*** Member not found in the $($group[$i]) group!"; write-output ''}
$i +=1}
while ($i -ne $group.length)
}

ADGroupMembers | out-File 'c:\Pshell\PM\groupmemberdetails.txt'