Reputation: 141
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?
Upvotes: 5
Views: 37775
Reputation: 5460
# Start-Run, type:
powershell.exe -noprofile -command "[guid]::newguid()|Set-Clipboard"
Upvotes: 2
Reputation: 141
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.
Upvotes: 9
Reputation: 126922
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.
Upvotes: 1
Reputation: 354854
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?
Upvotes: 0