Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland asked on

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
Powershell

Avatar of undefined
Last Comment
Alex

8/22/2022 - Mon
Qlemo

What exactly does not work? I cannot see anything totally wrong.
ASKER
Alex

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
Michael Pfister

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
Alex

Hey ya,

I took that out already, same issue.

Thanks
Alex
Qlemo

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 ;-).
ASKER
Alex

Qlemo

d.png
That's the error I get now :(
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Qlemo

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.
Robert

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

Qlemo

Robert, using + $([char]34) + for including a literal double quote is overcomplicated. Instead, use `"    (backquote, double quote).
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Robert

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.
ASKER CERTIFIED SOLUTION
Alex

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question