È incredibile come si perdano le ore ogni volta che bisogna schedulare qualcosa tramite task scheduler di windows…. dato che questa cosa mi ha fatto perdere 1 ora e mezza ho pensato bene di scrivere questo articolo per fare risparmiare tempo a chi si trova nella stessa situazione.
Innanzitutto dobbiamo separare due situazioni: pre powerCli 6 e post powerCli 6 perché dalla versione 6, oltre al path di default che è cambiato, è stato tolto il file vim.psc1 dalla cartella della powerCli.
Ecco come impostare la “action” da eseguire nel task scheduler:
PRE PowerCli 6:
Program/script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments (optional):
-PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1” -command “&{Z:\ScriptFolder\ScriptName.ps1}”
POST PowerCli 6:
Program/script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments (optional):
-c “. \”C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\” $true; C:\ScriptFolder\ScriptName.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)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\” $true; D:\Path\to\my\script.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! 🙂