VMware Cloud Community
koolpavan007
Contributor
Contributor

How to set a PowerCLI script to run with Site Recovery Manger service account.

My PowerCLI script is below:-

Connect-VIServer 10.0.0.1

foreach($nic in (Get-Cluster -Name CPTHI05 | Get-VM -Name Vase*| Get-NetworkAdapter)){
    switch -regex ($nic.Name){
    '.+[1|2|3]'{Set-NetworkAdapter -NetworkAdapter $nic -Connected:$false -StartConnected:$false -Confirm:$false}
    '.+[4|5|6]'{Set-NetworkAdapter -NetworkAdapter $nic -Connected:$true -StartConnected:$true -Confirm:$false}
    }
}

Disconnect-VIServer 10.0.0.1 -Confirm:$false

Primary Site Recovery Manager SRM service account is :- JNJ\NAsupport

and Recovery Site Recovery Manager SRM service account is :- JNJ\MPsupport

Issue is:-

I have created the recover step in the Site Recovery manager recovery plan as below:-
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -file C:\Vaseline\vase.ps1

(If I loginto the PowerCLI console or command prompt manually with my domain account and run the script it will work fine... the same script if it runs from SRM Recovery Plan TEST or RUN this command will give below error:-

Once the SRM Test get complete I get below error under the SRM TEST History Report:-
Success: "File C:\Vaseline\vase.ps1 cannot be loaded because the execution of scripts is
disabled on this system. Please see "get-help about_signing" for more details.
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE
xception
+ FullyQualifiedErrorId : RuntimeException

"

I need help on how to configure my powercli script mentioned above to run with above mentioned SRM service accounts.

Thank You

0 Kudos
3 Replies
koolpavan007
Contributor
Contributor

SRM experts could you please check and try to help me .. Thank You

0 Kudos
prince1121
Enthusiast
Enthusiast

hi

his might be a solution, it's based on a trick to bypass the ExecutionPolicy.

You can feed PowerShell script lines form standard input.

The line you would pass to SRM would look something like this

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noprofile -command "Get-Content -Path C:\Vaseline\vase.ps1 |

________________________________
If at first you don't succeed, skydiving is not for you

http://imagicon.info/cat/5-59/vbsmile.png

0 Kudos
mal_michael
Commander
Commander

Hi,

(If I loginto the PowerCLI console or command prompt manually with my domain account and run the script it will work fine...

Did you log in with your personal account or with SRM service account?

You might need to allow script execution for that user - just log in with SRM service account and run the following command in powershell console:

Set-ExecutionPolicy -RemoteSigned

Michael.

0 Kudos