Link to home
Start Free TrialLog in
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
Avatar of Qlemo
Qlemo
Flag of Germany image

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

ASKER

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
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
Avatar of Alex

ASKER

Hey ya,

I took that out already, same issue.

Thanks
Alex
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 ;-).
Avatar of Alex

ASKER

Qlemo

User generated image
That's the error I get now :(
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.
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

Robert, using + $([char]34) + for including a literal double quote is overcomplicated. Instead, use `"    (backquote, double quote).
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
Avatar of Alex
Alex
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial