6

I've created this basic one-liner PowerShell script which executes if I run the ad cmdlet for AD and then the rest of the query. But trying to run them together in line it only seems to load the cmdlet and doesn't execute the rest of the cmd.

powershell.exe -command "&{Import-Module ActiveDirectory; Get-AdGroup -Server DC.Mydomain.com -filter 'name -eq "xxxx"'| set-Adgroup -Replace @{wWWHomePage='10.24.218.194'}}"

Why doesn't it run all together like this?

4 Answers 4

10

The answer was to escape the double quotes:

powershell.exe -noprofile -command "&Import-Module ActiveDirectory; Get-AdGroup -Server server.mydomain.com -filter 'name -eq *\"xxxx\"*'| set-Adgroup -Replace @{wWWHomePage='10.10.10.10'}"

Basically, I'm running this from SQL to update an ActiveDirectory attribute that isn't accessible with DSADD.

Sign up to request clarification or add additional context in comments.

Comments

2
# Start-Run, type:
powershell.exe -noprofile -command "[guid]::newguid()|Set-Clipboard"

Comments

1

It looks like a quoting issue. Try to replace the surrounding filter quotes with braces:

-filter {name -eq "xxxx"}

To avoid these kind of situations, when you have long list commands to execute, I suggest you put the commands in a script file and pass its path to the -File parameter.

Comments

0

If in doubt with complex commands you can try encoding them in Base64 and using -EncodedCommand. See powershell /? for an example.

Does the line work as intended when you enter it directly in PowerShell?

1 Comment

The line does work when I use it directly in powershell. If import the AD module then run the rest of it it works every time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.