I've been working with a script that does almost exactly what I need it to do. It will take a drive share path, grab the access control list, and export it to a .csv file for later editing. My problem is that I can't figure out how to pass multiple drive path values to the script. I would like to use a .txt or .csv file to feed the shares to the script, and let it run overnight. The origin site says to assign a variable at the command line, and use this command:
$allServersVariable -FilePath C:\Scripts\MyPermissionsScript.ps1 -ArgumentList "E:\list" | Export-Csv C:\Scripts\ScanResults.csv –NoTypeInformation
I cannot however get this command to work. I can however do the following, and process one share at a time:
.\MyPermissionsScript.ps1 \\\192.168.1.1\SharedFiles | Export-Csv C:\Scripts\ScanResults.csv -NoTypeInformation
Here is the script:
function Get-PathPermissions {
param (
[Parameter(Mandatory=$true)]
[System.String]${Path}
)
begin {
$root = Get-Item $Path
($root | get-acl).Access | Add-Member -MemberType NoteProperty -Name "Path" -Value $($root.fullname).ToString() -PassThru
}
process {
$containers = Get-ChildItem -path $Path -recurse | ? {$_.psIscontainer -eq $true}
if ($containers -eq $null) {break}
foreach ($container in $containers)
{
(Get-ACL $container.fullname).Access | format-list -property Path, AccessToString
}
}
}
Get-PathPermissions $args[0]
This has been driving me crazy. Any help is greatly appreciated!