Subscribe

Trouble running power shell script

As the title. I'm having trouble running a power shell script as part of my pre-and post-smvi

When I checked the log file, it says that the script cannot be loaded because the execution of scripts has been disabled on the system. I have gone into power shell and set the execution policy to be unrestricted yet I still get the same error.

Under what user context does a script run when it is initiated by SMVI?

ta

Re: Trouble running power shell script

Are you sure you have set the execution policy to RemoteSigned  ?

1) Verify your Current setting -> PS C:\> Get-ExecutionPolicy

2) set to remotesigned ->  PS C:\> Set-ExecutionPolicy RemoteSigned (be sure to run, execute PowerShell as an Administrator to do this)

Philippe L.

Re: Trouble running power shell script

no, it WAS set to RemoteSigned and I changed it to Unrestricted.  This is because trying to run PS scripts in SMVI was giving me the error that scripts had to be signed.  However I still get the error when running the script under SMVI.

Re: Trouble running power shell script: More info

I’m trying to run a powershell script as part of my SMVI backup, but I keep getting the error

C:\Program Files (x86)\NetApp\SMVI\server\log\scripts>C:\Windows\System32\WindowsPowerShell\v1.0\powershell -file "C:\Program Files (x86)\NetApp\SMVI\server\scripts\shutdownAndSnapshotincDeletePostBackup.ps1"

File C:\Program Files (x86)\NetApp\SMVI\server\scripts\shutdownAndSnapshotincDe

letePostBackup.ps1 cannot be loaded because the execution of scripts is disable

d on this system. Please see "get-help about_signing" for more details.

    + CategoryInfo          : NotSpecified: (Smiley Happy [], ParentContainsErrorRecordE

   xception

    + FullyQualifiedErrorId : RuntimeException

Now google says that I have to set the execution policy to remotesigned, but it was already set to remotesigned so I set it to the even more lax unrestricted –

Windows PowerShell

Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\nbida> Get-ExecutionPolicy

Unrestricted

PS C:\Users\nbida>

I have rebooted and still get the execution error.

In an effort to work out the context in which the script was running I issued an “echo %username%” command to a file and got

????

Odd I thought, so I did a “SET” command to a file.  The output from the “set” command was –

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

???????????????????????????????????????????????????4??????????????????????????4?

?????????????????????????4????????????????????????????4?????????????????????????

??????????????4????????????????????????????4????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????

There is obviously something wrong here, but I don’t know what it is.  Can anyone advise please?

Re: Trouble running power shell script

I've finally found out what the problem is, so I thought I'd post it to help out others.

It seems that the change to executionPolicy in powershell is specific to the version of powershell in which you invoke the command, that's 32-bit or 64-bit.

I set the execution policy in 64-bit but SMVI was using the 32-Bit one to run the script, so the script was still trying to run in restricted mode.

set the execution policy in 32-bit as well and now it runs.