It's incredible how many hours it takes every time you have to schedule something with the windows task scheduler…. this thing has cost me one hour and a half so I thought to write this article to save time to those who are in the same situation.
First we must separate two situations: pre powerCli 6 and post powerCli 6 because from version 6, in addition to the default path that has changed, the vim.psc1 file has been removed from the PowerCLI folder.
Here's how to set the “action” to be performed in task scheduler:
PRE PowerCli 6:
Program/script:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
Add arguments (optional):
-PSConsoleFile “C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIvim.psc1” -command “&{Z:ScriptFolderScriptName.ps1}”
POST PowerCli 6:
Program/script:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
Add arguments (optional):
-c “. \”C:Program Files (x86)VMwareInfrastructurePowerCLIScriptsInitialize-PowerCLIEnvironment.ps1” $true; C:ScriptFolderScriptName.ps1″
Dear Bioffa,
I was looking for a way to run a PowerCLI script automatically and found your article to be very helpful. However, since I’m running PowerCLI 6.5 (factually Release 1 build 4624819) your statement “POST PowerCli 6” was not working as expected.
I don’t know if this was an upgraded installation of PowerCLI or a fresh one on that machine, either way I’m running Windows Server 2012 R2 (64-bit of course) and the arguments path is as follows:
-c “. \”C:Program Files (x86)VMwareInfrastructurePowerCLIScriptsInitialize-PowerCLIEnvironment.ps1” $true; D:Pathtomyscript.ps1″
It seems that over time VMware has changed the path pattern and since this might be helpful also to others I would like to add that statement / comment to your blog.
Cheers
Hi and thank for your comment! Sorry but I can’t see the difference between the two arguments, could it be a quotation mark error? WordPress always messes up with them….
Hey Bioffa,
I just noticed that some of the backslashes have been removed. The major difference was that the old path showed something like “Vmware PowerCLI” which has been changed to “PowerCLI” as a directory name only. I posted the correct path in my post but it has been changed by your blog system I’m afraid.
Strange thing is that now your original post also has changed. What went wrong?
I really don’t know!!! I know for sure that wordpress always messes up everything about double quotes, backslashes etc… but for the path I always saw it correct. Anyway thank you for the clarification, and yes the powercli default installation path has changed with the latest releases! 🙂