0

It seem like everyone who answers this question skirts the issue by giving example that either A. Aren't relevant; or, B. Use the -scriptBlock version.

Here is what I want: I want to run a PowerShell script from my local machine, on a remote machine. I need to pass in an argument or parameter.

Here is what I'm doing:

$responseObject = Invoke-Command -ComputerName MININT-OU9K10R -FilePath C:\Users\Documents\RemoteProofOfConcept\validatePath.ps1 -ArgumentList $filename  -AsJob

I want to pass $filename into the validatePath.ps1 script, and I can't figure out how to do this.

Can someone please show me how to do this, or tell me what I'm doing wrong?

None of these links have helped:

Get script directory in PowerShell when script is invoked with Invoke-Command

Powershell Invoke-Command with-FilePath Gives ItemNotFoundException

How do I pass named parameters with Invoke-Command?

1
  • No, that is the point. That file is on my local machine. If it were on the remote machine, I realize I could use the -scriptblock, but that isn't the case. I want to run local scripts on remote machines, and be able to pass in parameters to those scripts. Commented Jul 11, 2013 at 21:13

1 Answer 1

1

This works on PowerShell v3. Are you on V2?

9# gc .\foo.ps1
param($myarg)

hostname
"parameter value of myarg is $myarg"
10# $filename = "c:\foo.txt"
11# Invoke-Command Beagle2 -FilePath .\foo.ps1 -ArgumentList $filename
BEAGLE2
parameter value of myarg is c:\foo.txt

BTW, foo.ps1 doesn't exist on the remote computer. It is being transported by PowerShell to the remote computer for execution. Now if $filename contains a local computer path, I'm not sure how that would work on the remote computer unless it points to a file that is common to both computers.

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

Comments

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.