Forum Discussion
DarrenRD
Jul 09, 2021Copper Contributor
get-content and foreach loop
Hi I am trying to set permissions to all GPOs names in the file. I got the first PS script working by using -eq to name of a GPO in the file, but i need to set permissions to all GPOs in the file...
psophos
Jul 10, 2021Brass Contributor
$_ references the current item in the pipeline but not in a foreach loop.
Inside your foreach loop $gpo references each item loaded from the file.
So your if statement and Set-GPPermission should reference $gpo and not $_
Inside your foreach loop $gpo references each item loaded from the file.
So your if statement and Set-GPPermission should reference $gpo and not $_
DarrenRD
Jul 11, 2021Copper Contributor
psophos farismalaeb TY you both! . your comments got me thinking .. since my file may also contain non-exist GPOs in the domain i decided to use the Try and Catch. and seem to be the only way i got it working! see the screenshot