ccatano2000
Contributor
Contributor

Calling PowerCLI script from a batch file

Jump to solution

Hi all,

I am fairly new to using PowerCLI,  but have already seen the benefits of using it to help manage and administer a large infrastructure,  we have about 50 hosts using esx4i,  and it has been very useful.  I have a problem though in trying to run a health check,  I want to create a batch file that calls a .ps1 script and then schedule it as a task...  However,  here is the batch file code :

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{c:\scripts\myscript.ps1}"

it comes up with this in the cmd prompt after running the batch file :

Please specify a VI Server name eg....
      powershell.exe vCheck.ps1 MyvCenter

However I have the Connect-Viserver connection code in the myscript.ps1 ... The script runs great from PowerCLI ,  does anyone know what I am missing ?  Thanks for your help....any input would be appreciated.

chris

0 Kudos
1 Solution

Accepted Solutions
Troy_Clavell
Immortal
Immortal

I'm not much of a PowerCLI person, but you don't have to create a batch file.  Just paste the line of text below into your Windows OS scheduled task.  We usually set the run as: with an account with rights to vCenter.  Also, make sure the box to run only if logged in is unchecked.

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile  "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1"  -command "&{c:\scripts\myscript.ps1}"

View solution in original post

0 Kudos
1 Reply
Troy_Clavell
Immortal
Immortal

I'm not much of a PowerCLI person, but you don't have to create a batch file.  Just paste the line of text below into your Windows OS scheduled task.  We usually set the run as: with an account with rights to vCenter.  Also, make sure the box to run only if logged in is unchecked.

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile  "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1"  -command "&{c:\scripts\myscript.ps1}"

0 Kudos