查找共享网络文件夹和 Active Directory 信息

发布于 2025-01-16 14:45:55 字数 1947 浏览 0 评论 0原文

我有一个脚本,用于尝试查找共享网络文件夹和子文件夹信息,例如文件夹所有者、与网络共享文件夹或子文件夹关联的 AD 组、AD 组注释、AD 组描述、AD 组管理器和 AD群组经理电子邮件。

我目前很难弄清楚为什么当我将其导出到 .csv 文件时没有显示任何数据。我将不胜感激任何帮助或指导。

# Find the owner of the Network Folders and the AD Groups they got access to and the details of those AD Groups (name, description, managedby and ema $FolderPath = $DomainName =
Start-Transcript $PSScriptRoot\Transcript.txt

$FolderPath = "\\server\foldername"
$DomainName = "Domain"       # as in   Domain\ADGroupName

write-Host "Getting All the permissions of a Folder and its subfolder..."
$ACLS = @()
$Acls += Get-Item $FolderPath | get-acl
$ACLs += Get-ChildItem $FolderPath -Recurse -Directory

$results = @()

foreach($acl in $acls)
{
    $Domain = $DomainName.Split(".")[0]
    write-Host "  Getting Access ADGroup details"
    $AllDomainAccess = $acl.Access | Where-Object { $_.identityReference -like "$Domain\*" }

    foreach($DomainAccess in $AllDomainAccess)
    {
        $ADGroup = $null
        $ADGroup = get-ADGroup $($DomainAccess.IdentityReference).value.split("\")[-1] -Properties * -server $DomainName  -ea SilentlyContinue

        if($null -ne $ADGroup)
        {
            $data = '' | Select-Object FolderPath, FolderOwner, AccessGroup, AccessGroup_Description, AccessGroup_ManagedBy, AccessGroup_ManagerEmail
            $data.FolderPath = $acl.Path.split(":")[-1]
            $data.FolderOwner = $acl.Owner
            $data.AccessGroup = $ADGroup.Name
            $data.AccessGroup_Description = $ADGroup.Description
            $data.AccessGroup_ManagedBy = $ADGroup.ManagedBy
            $data.AccessGroup_ManagerEmail = $(get-aduser $($ADGroup.ManagedBy) -Properties mail).mail

            $results += $data
        }

}
}

$results | export-csv "$PSScriptRoot\NetworkFolderPermissions.csv" -NoTypeInformation
write-Host "Saved the results in $PSScriptRoot\NetworkFolderPermissions.csv" -ForegroundColor Green

Stop-Transcript

I have a script that I'm using to try to find Shared network folder and subfolder information such as the folder owner, AD groups associated to the Network shared folder or subfolder, AD group notes, AD group description, AD group manager, and AD group manager email.

I'm currently having a hard time trying to figure out why none of this data is showing when I export this to a .csv file. I would appreciate any help or guidance.

# Find the owner of the Network Folders and the AD Groups they got access to and the details of those AD Groups (name, description, managedby and ema $FolderPath = $DomainName =
Start-Transcript $PSScriptRoot\Transcript.txt

$FolderPath = "\\server\foldername"
$DomainName = "Domain"       # as in   Domain\ADGroupName

write-Host "Getting All the permissions of a Folder and its subfolder..."
$ACLS = @()
$Acls += Get-Item $FolderPath | get-acl
$ACLs += Get-ChildItem $FolderPath -Recurse -Directory

$results = @()

foreach($acl in $acls)
{
    $Domain = $DomainName.Split(".")[0]
    write-Host "  Getting Access ADGroup details"
    $AllDomainAccess = $acl.Access | Where-Object { $_.identityReference -like "$Domain\*" }

    foreach($DomainAccess in $AllDomainAccess)
    {
        $ADGroup = $null
        $ADGroup = get-ADGroup $($DomainAccess.IdentityReference).value.split("\")[-1] -Properties * -server $DomainName  -ea SilentlyContinue

        if($null -ne $ADGroup)
        {
            $data = '' | Select-Object FolderPath, FolderOwner, AccessGroup, AccessGroup_Description, AccessGroup_ManagedBy, AccessGroup_ManagerEmail
            $data.FolderPath = $acl.Path.split(":")[-1]
            $data.FolderOwner = $acl.Owner
            $data.AccessGroup = $ADGroup.Name
            $data.AccessGroup_Description = $ADGroup.Description
            $data.AccessGroup_ManagedBy = $ADGroup.ManagedBy
            $data.AccessGroup_ManagerEmail = $(get-aduser $($ADGroup.ManagedBy) -Properties mail).mail

            $results += $data
        }

}
}

$results | export-csv "$PSScriptRoot\NetworkFolderPermissions.csv" -NoTypeInformation
write-Host "Saved the results in $PSScriptRoot\NetworkFolderPermissions.csv" -ForegroundColor Green

Stop-Transcript

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文