Powershell:检查服务器上的文件夹权限并导出到本地计算机

问题描述 投票:0回答:1

美好的一天, 我想检查服务器上的文件夹权限并将结果以 csv 格式导出到本地计算机上的共享文件夹。 我认为 Enter-pssession 是可行的方法,但它找不到我要检查的文件夹。 看起来它是在本地计算机上查找该文件夹,而不是在服务器上。

这就是我所拥有的:

#Start of script

#Get Servername
$Servername = Read-Host -Prompt "Servername"
$Adminusername = Read-Host -Prompt "Admin user name"

#Connect to the server
Enter-PSsession $Servername -Credential $Adminusername

#Get the Directory
$Directory = Read-Host -Prompt "What directory and subfolders do you want to check (f.e. E:\Data\Shared_Data)?"

#Define location of export file
$path = "\\shared folder on local computer\"
$Logdate = Get-Date -Format yyyyMMddHHmm
$csvfile = $path + "\Permissions_$Servername_$LogDate.csv"

#Scan for directories under shared folder and get permissions for all of them
dir -Recurse $Directory | where { $_.PsIsContainer } | % { $path1 = $_.fullname; Get-Acl $_.Fullname | % { $_.access | Add-Member -MemberType NoteProperty '.\Application Data' -Value $path1 -passthru }} | Export-Csv -path $csvfile -NoTypeInformation -inputObject { $_; Write-Progress "Exporting to CSV" "$($_) " }

Write-Host
Write-Host "Export completed"
Write-Host
Read-Host -Prompt “Press Enter to return to the menu”

#End of script

我怎样才能让它发挥作用?

powershell server permissions
1个回答
0
投票

抱歉回复晚了。 我希望 powershell 连接到服务器并检索 f.i. 的文件夹权限。文件夹:E:\data\Shared_data。我知道这个文件夹存在于服务器上,但是当我运行脚本时,它给了我这个错误:

dir : Cannot find drive. A drive with the name 'e' does not exist.
At C:\Users\username\Desktop\Active Directory Scripts\Server permission checks 1.ps1:25 char:1
+ dir -Recurse $Directory | where { $_.PsIsContainer } | % { $path1 = $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (e:String) [Get-ChildItem], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

看起来它是在本地计算机上查找 E:\data\Shared_data 而不是服务器?

© www.soinside.com 2019 - 2024. All rights reserved.