Link to home
Start Free TrialLog in
Avatar of creative555
creative555

asked on

Issue with the script. Please help ASAP

Hi,
I ran the the script below and I am comparing before and after permissions, and seems that it added additional groups that were NOT in the excel file.....

Please help ASAP

Can someone tell me if it is possible or I am thinking that i am going crazy?

So, if I am not crazy then this script would not read the entire group name but only part of the group name and would add  all the groups that are beginning with this name. For example.

I only was suppose to add the group
TARGET01-NYC-DSC-MGM-SEcurityTEST

But now I see that addtional groups were added such as
TARGET01-NYC-DSC-MGM-SEcurityTEST
TARGET01-NYC-DSC-MGM-somethingelse1
TARGET01-NYC-DSC-MGM-somethingelse2

Below is the script:


Import-Csv Permissions3.csv | ForEach-Object {

  # Some defaults
  $InheritanceFlags = "containerInherit, ObjectInherit"
  $PropagationFlags = "None"

  # Override defaults if necessary
  $Inheritance = $_.InheritanceFlags
  Switch ($Inheritance) {
    "Subfolders and Files only"                      { $PropagationFlags = "InheritOnly" }
    "This Folder, One level of Subfolders and Files" { $PropagationFlags = "NoPropagateInherit" }
    "This folder and subfolders"                     { $InheritanceFlags = "ContainerInherit" }
    "Subfolders only"                                { $InheritanceFlags = "ContainerInherit"; $PropagationFlags = "InheritOnly" }
    "This folder and files"                          { $InheritanceFlags = "ObjectInherit" }
    "This folder and one level of files"             { $InheritanceFlags = "ObjectInherit"; $PropagationFlags = "InheritOnly" }
    "This folder only"                               { $InheritanceFlags = "None" }
  }

  # Build an access rule based on the line we read from the file
  $AccessRule = New-Object Security.AccessControl.FileSystemAccessRule(
    $_.Users, $_.FileSystemRights, $InheritanceFlags, $PropagationFlags, $_.AccessControlType)

  # Get the current access list
  $Acl = Get-Acl $_.UNCPath
  # Add the rule
  $Acl.AddAccessRule($AccessRule)
  # Save changes
  Set-Acl -Path $_.UNCPath -AclObject $Acl
}

Open in new window

Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

Check the file Permissions3.csv if you have some blank or unformatted lines: your script is looping for lines generating unexpected results.
Otherwhise you should check each line for missing information.
Avatar of creative555
creative555

ASKER

Hey,

I dont see any unformatted lines, but I see spaces in a lot of group names as below. You see there is a space before support. How to make script to put quotes around names so that it take entire group name that is listed in the excel? Could this be a problem?

AHX-DC\Target-DSC-AMER-PC Support
AHX-DC\Target-DSC-AMER-PC Support
AHX-DC\Target-DSC-AMER-PC Support
AHX-DC\Target-DSC-AMER-PC Support
Actually I am wrong. There was no spaces in the group name but dashes...

BElow is the group that I was adding:

TARGET-DSC-USPKG-GENDUP-FIL-GROUP

And two groups below also got added. As you can see, they have dashes NOT spaces
TARGET-DSC-USPKG-FIL-OPSMAN
TARGET-DSC-USPKG-FIL-SUPS
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is the entire content of lines our csv file or it's only a single column of that file?

The import-csv try to read each line separated by a character.
If a line contains more columns than expected your script will fail.

Some columns like Users, FileSystemRights, AccessControlType, UNCPath
must not contain the column separator character and there will be in the same order and count.
You can try to enclose into " each value that contains spaces or special characters like the separator used. It it's all ok then you need to check in another side or try to debug your file printing the parsed values on each line.


Import-Csv Permissions3.csv | ForEach-Object {

echo $_.Users
echo $_.FileSystemRights

...

}

Open in new window

Since the default delimiter is a comma, this cannot be the issue, fraigor. Import-CSV is only using a single, specific delimiter.
The other statement (too many columns) is also false.
Thank you so much. You are correct that this cannot be an issue. I verified again and it is all good!!
Script is good! thank you. I did add those groups :)