VMware Cloud Community
UofS
Enthusiast
Enthusiast
Jump to solution

powerCLI modules not loading

I am at a loss.

I have a PowerCLI script which fires on a "VM created event" in vCenter

The script runs a batch file which looks like

PowerShell.exe -file "C:\Scripts\alarms\VMcreated\scriptName.ps1" >> c:\temp\log.txt

scriptName.ps1 basically does

    . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

     Connect-ViServer

I end up getting Connect-VI: Command does not exist.

I seems that the script is not loading the modules when running as the system account without a shell but does as the system user when in a shell.

I have run this manually as the nt authority\system user is a ps shell started by psexec and it works great.

If I put a Get-VICommand in there it works but has no commands available.

Any ideas why it wont work?

Using Windows 2012R2 for VCenter and Power CLI 6.3 U1

Script attached.

Dion

This has come about as I have to implement this on a new 6.0 vCenter server (as we had it setup on 5.5):

http://blogs.vmware.com/PowerCLI/2009/09/how-to-run-powercli-scripts-from-vcenter-alarms.html

0 Kudos
1 Solution

Accepted Solutions
UofS
Enthusiast
Enthusiast
Jump to solution

I finally in desperation rebooted the windows system and now everything is working fine.

We have no idea how it got into that state and have tried to replicate possible actions that may have made this happen and have unable to make it fail again.

Very strange.  But lessoned learned.

If in doubt.  Reboot.  I thought we were past those days, but alas.

Thanks.

Dion

Update:  Exact same thing happened in production.  Rebooted server - problem solved again.  Weird.

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try adding a Get-ExecutionPolicy cmdlet to your script ?

What does it say in the output ?

Can you capture the output of the script with a Start-Transcript cmdlet at the beginning ?


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

0 Kudos
UofS
Enthusiast
Enthusiast
Jump to solution

Here are the log and script

It responds

RemoteSigned

0 Kudos
UofS
Enthusiast
Enthusiast
Jump to solution

I finally in desperation rebooted the windows system and now everything is working fine.

We have no idea how it got into that state and have tried to replicate possible actions that may have made this happen and have unable to make it fail again.

Very strange.  But lessoned learned.

If in doubt.  Reboot.  I thought we were past those days, but alas.

Thanks.

Dion

Update:  Exact same thing happened in production.  Rebooted server - problem solved again.  Weird.

0 Kudos