Hi Guys,
I am tasked with getting an automated method to collect the windows ACL lists for a bunch of pre-defined paths on some servers. I am going with powershell on this one.
1. Get ACL lists of predefined paths
2. Output results to excel and then save the file at the end.
Here is what I have so far:-
$a = Get-Content "C:\Scripts\pathlist.txt"
foreach ($i in $a)
{
#### Set Excel Sheet properties ####
$excel = new-object -comobject excel.application
$excel.visible = $true
$workbook = $excel.workbooks.add()
$workbook.workSheets.item(3).delete()
$workbook.WorkSheets.item(2).delete()
$workbook.WorkSheets.item(1).Name = "ACL List"
$sheet = $workbook.WorkSheets.Item("ACL List")
#### set the row level to start outputting data ####
$x = 2
#### Get Object ACL ####
foreach ($folder in $object=Get-ChildItem $i -recurse | Where-Object {$_.PsIsContainer -eq $true} | Get-Acl)
{
#### Give title names to each column ####
$sheet.cells.item(1,1) = "Path"
$sheet.cells.item(1,2) = "Owner"
$sheet.cells.item(1,3) = "Group of Owner"
$sheet.cells.item(1,4) = "Access"
$sheet.cells.item($x,1) = $folder.path
$sheet.cells.item($x,2) = $folder.owner
$sheet.cells.item($x,3) = $folder.group
$sheet.cells.item($x,4) = $folder.access
$x++
}
#### adjust zie of columns ####
$range = $sheet.usedRange
$range.EntireColumn.AutoFit() | out-null
#### save excel workbook ####
$strPath = "C:\scripts\results\results.xls"
IF(Test-Path $strPath)
{
Remove-Item $strPath
$Excel.ActiveWorkbook.SaveAs($strPath)
}
ELSE
{
$Excel.ActiveWorkbook.SaveAs($strPath)
}
}
It doesn't work thus far and I am thinking that my foreach loop isnt working when collecting $object, simply because its parsing lot's of lines of info into the variable rather than one row at a time. My question is...how would i get a row at a time to put in excel, i mean if I output to a text file with format list it puts spaces in the data where needed. Also I think I am calling on the correct member types for $folder but I am not 100% sure.
Anyone doing something simular or can help me out!
Cheers,
Pash