Very quick powershell question

Morning all

So

$CountryCodes = "AE-DUB-LME", "$CountryCode", "CN-BEI-LEB", "IN-NSK-LEI", "IN-PUN-FZE", "IN-VAD-LEI", "MY-KUL-LAP", "SA-ALK-LSA", "SA-JED-LSA", "SA-RIY-LSA", "TH-BKK-LET", "TH-RAY-LET", "UK-AXD-AXL", "UK-AXL-AXL", "UK-BAN-LEL", "UK-BIR-LC", "UK-MIL-LZ", "UK-OXF-LOX", "UK-OXF-LPO", "UK-SOW-LZ", "UK-THM-LEL", "UK-WIT-LC", "ZA-JOH-LZA"

ForEach ($CountryCode In $CountryCodes) {

# Group memberships
dsacls "ou=$CountryCode,ou=groups,ou=Something,dc=COmpnayt,dc=com" /I:S /G "DOmain\Del-AD-$CountryCode-Grp-Mbr":rpwp;member;group
}

Open in new window


This is running the DSACLS via powershell, but funny this, it's not working. Do I just need to put a & behind the DSACLS?

Thanks
Alex
LVL 17
Alex Green3rd Line Server SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
What exactly does not work? I cannot see anything totally wrong.
0
Alex Green3rd Line Server SupportAuthor Commented:
The parameter is incorrect.


The command failed to complete successfully.
member : You must specify an object for the Get-Member cmdlet.
At line:1 char:116
+ ... dc=com" /I:S /G "company\Del-AD-$CountryCode-Grp-Mbr":rpwp;member;group
+                                                              ~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
0
Michael PfisterCommented:
1)
$CountryCodes = "AE-DUB-LME", "$CountryCode", ...

Open in new window

   Whats the variable doing here?

2) add before dsacls
cmd /c  echo dsacls ...... >> log.txt

Open in new window

Check log.txt if the systax is correct
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Alex Green3rd Line Server SupportAuthor Commented:
Hey ya,

I took that out already, same issue.

Thanks
Alex
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Your call should look like
dsacls "ou=$CountryCode,ou=groups,ou=Something,dc=COmpnayt,dc=com" /I:S /G "DOmain\Del-AD-${CountryCode-Grp-Mbr}:rpwp;member;group"

Open in new window

to prevent PowerShell from interpreting too much into it ;-).
0
Alex Green3rd Line Server SupportAuthor Commented:
Qlemo

d.png
That's the error I get now :(
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I recommend to build up a valid and working single dsacls command manually first. If that works, you can try to integrate that into the PS script using variables.
0
RobertSystem AdminCommented:
This is just my opinion however I like using Invoke-expression, it simplifies and prevents some issues with using variables in command line utilities.

(note for the example did not confirm the syntax of your DSACLS command)
for example
$command = "dsacls + $([char]34) +ou=$CountryCode,ou=groups,ou=Something,dc=COmpnayt,dc=com + $([char]34) + /I:S /G + $([char]34) + DOmain\Del-AD-$CountryCode-Grp-Mbr + $([char]34) +:rpwp;member;group"
invoke-expression $command

Open in new window

0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Robert, using + $([char]34) + for including a literal double quote is overcomplicated. Instead, use `"    (backquote, double quote).
0
RobertSystem AdminCommented:
Your are correct that you could just use the quotes, i just got in habit of using the expression as it is easier for me to see at quick glance.
0
Alex Green3rd Line Server SupportAuthor Commented:
Did it manually and changed the names.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.