Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:24:28+00:00 2026-05-27T14:24:28+00:00

I want to use Powershell in order to call a batch file on remote

  • 0

I want to use Powershell in order to call a batch file on remote machines. This batch file has arguments. Here’s what I have so far:

$script = "\\fileshare\script.cmd"
$server = $args[0]
$args [string]::join(',',$args[1 .. ($args.count-1)])

Invoke-Command -computername $server {$script + ' ' + $args}

After a bit of searching, I found that the Invoke-Command function runs its scriptblock in a whole new process, so you can’t put variables in it (they won’t get expanded). That’s what the -ArgumentList tag is for. So I tried this instead…

Invoke-Command -computername $server {\\fileshare\script.cmd} -ArgumentList "FirstArgument"

That didn’t work either… my batch script tells me it’s not being passed any arguments. I can’t find anything that explicitly says so, but it looks like the -ArgumentList parameter only works on Powershell scripts (it won’t feed them to a batch script).

Any ideas how I can use Invoke-Command to call a batch file with arguments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:24:28+00:00Added an answer on May 27, 2026 at 2:24 pm

    When you pass the argument list to the scriptblock, try to “receive them” using a PARAM directive. Like this:

    Invoke-Command -computername $server {PARAM($myArg) \\fileshare\script.cmd $myArg} -ArgumentList "FirstArgument"
    

    or you can just use the $args automatic variable:

    Invoke-Command -computername $server {\\fileshare\script.cmd $args} -ArgumentList "FirstArgument"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following XML file, and I want to use PowerShell (version
I have several Powershell scripts that I want to execute on 4 remote machines.
I have a transaction log file in CSV format that I want use to
I want to use Powershell to write some utilities, leveraging our own .NET components
i want use some data from a website with web service. i have a
I am really very new to powershell. I want to use powershell to read
Update, Script is working with PowerShell V3.0, Thanks @ Doug I want to use
I want to parallelize some file-parsing actions with network activity in powershell. Quick google
I want to use PowerShell to transfer files with FTP to an anonymous FTP
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.