0

I'm having a System.Array that defines the permissions of a specific security group on a folder, which looks like this:

$Permissions
C\Department                     : FINANCE
BEL ROL-STAFF-FIN Accountants    : L
BEL ROL-STAFF-SA Sales Employees : F

C\Department                     : SALES
BEL ROL-STAFF-FIN Accountants    : C
BEL ROL-STAFF-SA Sales Employees : F

$Permissions.Count # Returns 2

What I would like to know is how can I add another security group?

If I would like to add the security group BEL ROL-STAFF-IT Service Desk with the value F to the example above, the result would be:

$Permissions
C\Department                     : FINANCE
BEL ROL-STAFF-FIN Accountants    : L
BEL ROL-STAFF-SA Sales Employees : F
BEL ROL-STAFF-IT Service Desk    : F

C\Department                     : SALES
BEL ROL-STAFF-FIN Accountants    : C
BEL ROL-STAFF-SA Sales Employees : F
BEL ROL-STAFF-IT Service Desk    : F

$Permissions.Count # Returns 2

It seems easy to just add a row to an array, but how does one add a key/value pair to an existing row in the array so the count stays the same?

Thank you for your help.

2 Answers 2

1

add an hashtable to your array

$i=0
$permissions|%{
    $permissions[$i]+=@{'BEL ROL-STAFF'='F'}
    $i++
}
Sign up to request clarification or add additional context in comments.

Comments

0

Found it, I had to add a NoteProperty to a single rowor $Item as I named it below:

[int]$i = '0'
foreach ($Item in $Permissions) {

    Write-Host "Item $([int]$i++)" -ForegroundColor Yellow
    $Item

    foreach ($d in $DefaultPermissions) {
        Add-Member -InputObject $Item -MemberType NoteProperty -Name $d.GroupName -Value $d.Permissions
    }

    $Item
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.