how to get it right? one single object output

by Feb 26, 2014


I am trying to move from quick and dirty to production ready.

The script I am writting should go thru a share and get all the NTFS permissions that they are not inherited and for the groups get a list of users members of that group.

I have been following Toolmaking book from Don Jones and I am trying to create a first attemp to create a scrpt that only outputs one single object.

So i create a Pscustom object $obj.

Still in draft but so far my script looks something like that.

The issue I am facing is with processing the"groups", if I try to expand it I am not able to otuput it properly to a csv file which it is my intention.

Any advice on taking me on the right direction about how to properly scripts, it is very welcome.



function Get-NTFSPermissions {
This scripts will generate an object info from the HZI share

Specify the root folder from where we are going to audit the permissions
Specify this switch to create a text log file of folders that could not be quiery
param (
[Parameter( Mandatory=$true,
HelpMessage="Provie the list of Folders")]
# System.IO.DirectoryInfo
# [switch]$Logerrors,
# [string]$errorlog = (dir env:temp).value + "errors.txt"

Write-Verbose "Error log will be $errorlog"

Write-Verbose "Beginning Process Block"
foreach ($folder in $Folders) {
Write-Verbose "Querying $folder"
$ACLs = Get-Acl $folder | select-object -ExpandProperty access | where-object { $_.IsInherited -like "False" }
Write-Host $ACLs
if ($ACLs) {
foreach ($acl in $ACLs) {
#$usuarios = @()
$group = $acl.IdentityReference.value.Split("")[1]
if (get-adgroupmember $group) { $usuarios = get-adgroupmember $group | select -ExpandProperty name }
$props = [ordered]@{'Folder' = $folder 'User' = $acl.IdentityReference
'Permission' = $acl.FileSystemRights
'Groups' = $usuarios
#$usuarios = $null
$obj = new-object -type PSObject -Property $props
write-output $obj






I would like to thank the people who takes their time to help out others in this forum. it is very much appreciated it.