how to get it right? one single object output

by Feb 26, 2014

Hi,

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 {
<#
.SYNOPSIS
This scripts will generate an object info from the HZI share
.DESCRIPTION

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

BEGIN {
Write-Verbose "Error log will be $errorlog"
}

PROCESS {
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
}

}
}

}
END {

}
}
get-ntfspermissions

 

"

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

 

Regards,

Jacobo.