$acl = Get-Acl -Path "\\SharedFolderPath" $access = $acl.Access |where IdentityReference -Like "contoso\*" $DGroup = $access | ForEach-Object { $_.IdentityReference -replace "contoso\\",""} $GGroup = $DGroup -replace "D","G" $Users = $GGroup | ForEach-Object {Get-ADGroupMember -Identity $_ } $ACLInformation = $Users | ForEach-Object { Get-ADUser -Identity $_.Name -Properties * |Select-Object Name,displayname,Company,Department }
我最后想导出一个csv文件,里面包含SharedFolderPath、Group、Access(C\R)、UserName、Displayname、Company、Department这几项。
万分感谢!
本文链接: https://www.pstips.net/merge-multiple-output-into-a-csv.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
提问请发送至问答中心:http://www.pstips.net/dwqa-questions/
本站不帮忙写脚本,只提供思路。
你的需求很清楚:获取共享文件路径的访问者(用户)信息,同时再在AD中获取一些基本的用户信息,比如display name,部门等。
假定这些信息都已经获取了,并且是一个数组了:$shareFileUserinfos。
导出就简单了:$shareFileUserinfos | ConvertTo-Csv | Out-File ‘d:\pstips.net.txt’
关键点是怎么构造$shareFileUserinfos,Get-Acl返回的信息中有的用户是本地用户,有的是域用户,你得把本地用户给排除了。其次通过域用户的alias,去AD中获取具体的用户信息。
Mooser,很高兴收到你的回复,我昨天用的是new-object的方法来实现了我的需求,只不过需要嵌套三层foreach循环,以此来实现我的需求。
Import-Module ActiveDirectory
$FolderPath = Import-Csv C:\SharePath.csv
$FolderPath | ForEach-Object {
$Path = $_.FolderPath
$acl = Get-Acl -Path “$Path”
$access = $acl.Access |where IdentityReference -Like “AIA\*”
$access | ForEach-Object{
$Level = $null;
if($_.IdentityReference -like “*C”){$Level = “Change”}
else{$Level = “Read”}
$D_Group = $_.IdentityReference -replace “AIA\\”,””;
$G_Group = $D_Group -replace “-D-“,”-G-“;
$Users = Get-ADGroupMember -Identity $G_Group
$Users | ForEach-Object{
$UserInfo = Get-ADUser -Identity $_.Name -Properties *
$info = @{
‘Path’ = $Path;
‘Group’ = $D_Group;
‘Class’ = “Group”;
‘Level’ = $Level;
‘UserID’ = $UserInfo.Name;
‘UserName’ = $UserInfo.Displayname;
‘Company’ = $UserInfo.Company;
‘Department’ = $UserInfo.Department
}
New-Object -TypeName PSObject -Property $info |Select-Object Path,Group,Class,Level,UserID,UserName,Company,Department |Export-Csv C:\ACL.csv -Encoding UTF8 -NoTypeInformation -Append -Force
}
}
}
不知道对于我这个脚本你有没有优化的建议,希望以后能够多和你交流,谢谢!