VMware Cloud Community
olczak
Enthusiast
Enthusiast
Jump to solution

PowerCLI script not executed from SRM command line

Hi,

Even If I set the PowerShell Execution policy to Unrestricted, when I try to launch a script from a Commad line step added in SRM, the script is not executed. In the SRM log I can find:

[#2]    dynamicType = <unset>,

[#2]    faultCause = (vmodl.MethodFault) null,

[#2]    result = (dr.secondary.CalloutResult) {

[#2]       dynamicType = <unset>,

[#2]       commandLine = "c:\windows\system32\cmd.exe /c C:\Source_code_VMware\Scripts\redirect.bat C:\CACINTEL\Source_code_VMware\Scripts\DRSrules_TEST.ps1",

[#2]       output = "File C:\Source_code_VMware\Scripts\DRSrules_TEST.ps1 cannot be loaded

[#2] because the execution of scripts is disabled on this system. Please see "get-he

[#2] lp about_signing" for more details.

[#2] At line:1 char:2

[#2] + & <<<<  'C:\\Source_code_VMware\\Scripts\\DRSrules_TEST.ps1'

[#2]     + CategoryInfo          : NotSpecified: (:) [], PSSecurityException

[#2]     + FullyQualifiedErrorId : RuntimeException

[#2] 

[#2] ",

[#2]       returnValue = 1,

[#2]    },

[#2]    msg = "",

Once again, the Execution policy is set to Unrestricted:

[vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-ExecutionPolicy -list

                                                         Scope                                               ExecutionPolicy
                                                         -----                                               ---------------
                                                 MachinePolicy                                                     Undefined
                                                    UserPolicy                                                     Undefined
                                                       Process                                                     Undefined
                                                   CurrentUser                                                     Undefined
                                                  LocalMachine                                                  Unrestricted

Obviously the command works fine if I launch it manualy from a command prompt...

Any idea?

Thanks by advance

0 Kudos
1 Solution

Accepted Solutions
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Make sure you set it in the 32bit version of PowerShell, SRM uses the 32 bit PowerShell host.

Thats the one that always gets me !

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com

View solution in original post

0 Kudos
8 Replies
alanrenouf
VMware Employee
VMware Employee
Jump to solution

You need to check which account your SRM service is running under, if its left to default it will be system, the powershell script is run under the context of the user which runs the SRM service by default.

You may need to change the service to run as a service account and then log in with this account to set the execution policy before running the script.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
olczak
Enthusiast
Enthusiast
Jump to solution

I already changed the SRM service to use a "Service Account".

The Powershell policy has been set when logged using this service account......

0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Make sure you set it in the 32bit version of PowerShell, SRM uses the 32 bit PowerShell host.

Thats the one that always gets me !

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
olczak
Enthusiast
Enthusiast
Jump to solution

Alan,

As always, you are the man !

Obviously I went into the trap and was setting the policy in the 64bit PowerCli session.

I even configured the Policy to RemoteSigned for a "better" security.

Thanks again for your extremly quick answer Alan.

0 Kudos
koolpavan007
Contributor
Contributor
Jump to solution

what is the solution for this error?

0 Kudos
koolpavan007
Contributor
Contributor
Jump to solution

I am also having same issue and my question is posted at :-

http://communities.vmware.com/thread/345482?tstart=0 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In the guest OS, under the SRM account, run

Set-ExecutionPolicy RemoteSigned


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
koolpavan007
Contributor
Contributor
Jump to solution

The exeuction poliy i have manually set it to unrestricted in both the SRM servers.

0 Kudos