INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Properly formatted Invoke-Command help

Properly formatted Invoke-Command help

(OP)
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\www.foo.com\httpd.conf -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 = "www.foo.com"
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?

RE: Properly formatted Invoke-Command help

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.

RE: Properly formatted Invoke-Command help

(OP)
Pure genius! It worked!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close