1

I am trying to run powershell script from my server machine on all machines in network. Firstly I am trying it with only 1 machine.

But, I am getting following error:

File C:\file.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:27
+ C:\file.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

I am using following command:

D:\Task\PSTools>PsExec.exe remotemachine -u domain\adminuname -p adminpwd cmd.exe \c start

PsExec v2.1 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>powershell.exe "C:\file.ps1"

So can you please help me in this.

Thanks in advance.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Aparna Rithe
  • 35
  • 1
  • 7

2 Answers2

0

Remote computers need to have their execution policy changed to allow the script to run. It's the same thing you probably had to do to run the script on the host computer during testing.

This can be accomplished via Group Policy or manually (on all of the computers).

Using PSExec you might be able to set the policy on individual computers by running the Set-ExecutionPolicy cmdlet.

Maha
  • 1
0

Change your powershell line to this to bypass local execution policy:

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File "C:\file.ps1"