Alex
asked on
Very quick powershell question
Morning all
So
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
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
}
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
What exactly does not work? I cannot see anything totally wrong.
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-$CountryCo de-Grp-Mbr ":rpwp;mem ber;group
+ ~~~~~~
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Micros oft.PowerS hell.Comma nds.GetMem berCommand
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-$CountryCo
+ ~~~~~~
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Micros
1)
2) add before dsacls
$CountryCodes = "AE-DUB-LME", "$CountryCode", ...
Whats the variable doing here?2) add before dsacls
cmd /c echo dsacls ...... >> log.txt
Check log.txt if the systax is correct
ASKER
Hey ya,
I took that out already, same issue.
Thanks
Alex
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"
to prevent PowerShell from interpreting too much into it ;-).
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
(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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.