We help IT Professionals succeed at work.

Very quick powershell question

Alex
Alex asked
on
101 Views
Last Modified: 2018-09-04
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
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
What exactly does not work? I cannot see anything totally wrong.
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

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
CERTIFIED EXPERT

Commented:
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
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
Hey ya,

I took that out already, same issue.

Thanks
Alex
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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 ;-).
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
Qlemo

d.png
That's the error I get now :(
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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.
RobertSystem Admin
CERTIFIED EXPERT

Commented:
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"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Robert, using + $([char]34) + for including a literal double quote is overcomplicated. Instead, use `"    (backquote, double quote).
RobertSystem Admin
CERTIFIED EXPERT

Commented:
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.
A lack of information provides a lack of a decent solution.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.