0
invoke-command -computer hq128804 -scriptblock {powershell.exe -nonprofile -executionpolicy Bypass c:\Install-WMF5.ps1} 

The Error:

Missing expression after unary operator '-'.
    + CategoryInfo          : NotSpecified: (Missing express...y operator '-'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : hq128804

At line:1 char:2
+ - <<<< nonprofile -executionpolicy Bypass c:\Install-WMF5.ps1
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
NotSpecified: (:) [], RemoteException

I am trying to run a script that is located on the root file system of another remote PC. I want to be able to execute this and update PowerShell for 2000 machines. I have the update files on each system, I just need a way to execute the .ps1 file Microsoft provides from my machine.

10
  • The script you invoke (Install-WMF5.ps1) has an error - your code example seems good. Commented Jun 6, 2017 at 19:10
  • That is microsofts script.... Commented Jun 6, 2017 at 19:11
  • Well - I was about to say "so? I had a script from M$ that could not work on W10 machines because of lazy coding...", but there must be another issue. Give me a second Commented Jun 6, 2017 at 19:12
  • 2
    Try without the typo nonprofile -> NoProfile Commented Jun 6, 2017 at 19:13
  • It is working... but it is hanging. It isn't producing an error or anything. I have executable rights. winrm is enabled. Commented Jun 6, 2017 at 19:25

1 Answer 1

0

You should do something like this:

Invoke-command -ComputerName hq128804 -scriptblock{powershell.exe -noprofile -executionpolicy Bypass -Command "& { c:\Install-WMF5.ps1}" }

Note: Make sure you are having the ps1 properly placed in the mentioned path

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.