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-SEcur ityTEST
But now I see that addtional groups were added such as
TARGET01-NYC-DSC-MGM-SEcur ityTEST
TARGET01-NYC-DSC-MGM-somet hingelse1
TARGET01-NYC-DSC-MGM-somet hingelse2
Below is the script:
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-SEcur
But now I see that addtional groups were added such as
TARGET01-NYC-DSC-MGM-SEcur
TARGET01-NYC-DSC-MGM-somet
TARGET01-NYC-DSC-MGM-somet
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
}
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
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
ASKER
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-FI L-GROUP
And two groups below also got added. As you can see, they have dashes NOT spaces
TARGET-DSC-USPKG-FIL-OPSMA N
TARGET-DSC-USPKG-FIL-SUPS
BElow is the group that I was adding:
TARGET-DSC-USPKG-GENDUP-FI
And two groups below also got added. As you can see, they have dashes NOT spaces
TARGET-DSC-USPKG-FIL-OPSMA
TARGET-DSC-USPKG-FIL-SUPS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
...
}
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.
The other statement (too many columns) is also false.
ASKER
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 :)
Script is good! thank you. I did add those groups :)
Otherwhise you should check each line for missing information.