1

我正在尝试获取我们服务器上所有文件夹的文件夹信息和安全信息。但是我在这里对Powershell并不熟悉。介意帮助新手吗?

如何将安全 acl 通过管道传输到文本文件中?除了文件夹名称、大小、子文件夹计数的成员对象吗?

# Step 1 Get Folder Path 
function Select-Folder($message='Select a folder', $path = 0) { 
    $object = New-Object -comObject Shell.Application  

    $folder = $object.BrowseForFolder(0, $message, 0, $path) 
    if ($folder -ne $null) { 
        $folder.self.Path 
    } 
} 


#Step 2:Search For Directories
$dirToAudit = Get-ChildItem -Path (Select-Folder  'Select some folder!') -recurse | Where {$_.psIsContainer -eq $true}

foreach ($dir in $dirToAudit)
{

#Step 3: Output: [Folder Path, Name, Security Owner, Size, Folder Count]
#Pipe To CSV Text File
    Get-Acl -Path $dir.FullName | Select-Object PSPath, Path,Owner | export-csv C:\temp\SecurityData.csv
    #I also want the Folder path, Size and SubFolder Count
}


#Step 4: Open in Excel 
invoke-item -path C:\temp\SecurityData.csv

以下是我发现对这个主题有用的一些网站:http: //blogs.msdn.com/b/powershell/archive/2007/03/07/why-can-ti-pipe-format-table-to-export-csv -and-get-something-useful.aspx

http://www.maxtblog.com/2010/09/to-use-psobject-add-member-or-not/

4

1 回答 1

2

这项任务并不是特别容易。首先,您需要创建一个包含所需属性的自定义对象。这些属性将通过不同的命令添加,例如:

$objs = Get-ChildItem . -r | 
            Where {$_.PSIsContainer} | 
            Foreach {new-object psobject -prop @{Path=$_.FullName;Name=$_.Name;FolderCount=$_.GetDirectories().Length}}
$objs = $objs | Foreach { Add-Member NoteProperty Owner ((Get-Acl $_.Path).Owner) -Inp $_ -PassThru}

$objs | Export-Csv C:\temp\data.csv

获取文件夹大小将需要一些额外的工作来计算。

于 2012-10-18T17:15:31.873 回答