Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Properly formatted Invoke-Command help

Status
Not open for further replies.
Nov 26, 2007
25
0
0
US
I am trying to run the command below on multiple computers so I want to use invoke-command. It works fine in powershell and command line all by itself. But when I use invoke command and pass variables the nightmare happens.:

Code:
D:\Apache\bin\httpd.exe -f D:\apacheconfig\[URL unfurl="true"]www.foo.com\httpd.conf[/URL] -k install -n www.foo.com

The problem I am having is trying to get this properly formatted in the invoke-command and passing variables using argument list. I can pass the variable correctly however the command is missing some single quote or double quotes. I just don't know where to put them.

Code:
$Server = "server123"
$FQDN = "[URL unfurl="true"]www.foo.com"[/URL]
invoke-command -ComputerName $Server -ScriptBlock {& 'D:\Apache\bin\httpd.exe' -f D:\apacheconfig\$args[0]\httpd.conf -k install -n $args[0]} -ArgumentList $FQDN


Error:
Code:
httpd.exe: Wildcard patterns not allowed in Include D:/ApacheConfig/www.foo.com[0]/httpd.conf
    + CategoryInfo          : NotSpecified: (httpd.exe: Wild...m[0].httpd.conf:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : server123

A few things I notice
1) Slashes are now forward slashes, not sure if that makes difference.
2) my argument still contains [0]

This is driving me crazy. Thanks for any help. Do I need to run any ps-session commands before hand?
 
Try this:

Code:
invoke-command -ComputerName $Server -ScriptBlock {& 'D:\Apache\bin\httpd.exe' -f D:\apacheconfig\$($args[0])\httpd.conf -k install -n $($args[0])} -ArgumentList $FQDN


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top