0
votes

Could anyone please offer me some hints? I am stuck with this problem.

I have developed a PowerShell script located in:

\\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1

This script requires 4 arguments to work. I need to run that script from another computer.

I have tried:

Invoke-Command -ComputerName ComputerNameA 
      -FilePath \\\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1  
      -ArgumentList {-arg0 string -arg1 string -arg2 string -arg3 string}

Any hints will be appreciated.

Update: As to answer my original question, I think the answer is: Invoke-Command -ComputerName ComputerNameA -Credential $cred -FilePath \\ComputerNameA.xxx.xxx.local\d\xxx\script.ps1
-ArgumentList {-arg0 string -arg1 string -arg2 string -arg3 string}

Now, the new problem is I got the access denied error even the credential is exist (i.e. I setup a new user account - abcd and set the password as abcd)

1
What's the error when you ran the script from another systemJawad
Thank you Jawad. I fixed the previous problem. I need to use " " for a folder name which contains a space. The new error message is: connecting to remote server ComputerNameA failed with the following error message: access is denied.Squirrel
Your invoke command needs credentials to access the other computer. You either need domain level access to run it, or use pssession to set credentials and then use them. or you can set them in the command with username parameter. docs.microsoft.com/en-us/powershell/module/…Robert Cotterman
Thank you Robert. I setup a new user account in ComputerNameA, make the user be member of "Users" and "PS Job Users". And also use -credential in invoke-command, but still failed with: AccessDenied, PSSessionStateBrokenSquirrel

1 Answers

-1
votes

You can try installing ssh server where the scripts is located then connect using putty for windows
then execute refer to this