VMware Cloud Community
glider777
Contributor
Contributor

How to run vCheck script as a scheduled task?

I can run vCheck straight form Powershell no problem. However when I add it to a scheduled task I get an email that returns nothing but the following:

Number of Hosts:

1

Number of VMs:

1

Number of Templates:

1

Number of Clusters:

1

Number of Datastores:

1

 

I of course have many more host etc than this. My task has the following settings:

script:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

arguments:

"C:\scripts\vCheck-vSphere-master\DC2\vCheck.ps1"

 

I have seen some blog posts regarding this but they all seem out of date. What am I missing?

0 Kudos
8 Replies
scott28tt
VMware Employee
VMware Employee

This thread would probably be better in the PowerCLI area, a moderator should be along to move it there.

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

Under which account does the Scheduled Task run?
How do you pass the VCSA credentials to vCheck in the Scheduled Task?
Did you use an XML file to specify against which environment vCheck should run?
Which outdated posts are you referring to?


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

0 Kudos
glider777
Contributor
Contributor

Under which account does the Scheduled Task run? - service account with RO permissions to vcenter
How do you pass the VCSA credentials to vCheck in the Scheduled Task? - no idea
Did you use an XML file to specify against which environment vCheck should run? - no
Which outdated posts are you referring to? - there are many posts about running the powershell and the arguments is powercli or somethign but those folders dont exist and none of that works.

0 Kudos
rclarke2
Contributor
Contributor

There are many methods of executing PowerCLI/POSH against a vCenter on a scheduled basis, the most common is using a cronjob or scheduled task, as described here https://virtualg.uk/running-powercli-powershell-scripts-as-a-scheduled-task/

0 Kudos
glider777
Contributor
Contributor

If I use the following from the article

  • Action: Start a Program
  • Program\Script will be the path to PowerShell, for example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Add arguments will be: -ExecutionPolicy Bypass -File “C:\Scripts\script.ps1”

I still only get an email sent which has 1 host, VM, Template, Cluster, datastore in the report from general information.

I dont get anything else, so something simply isn't working.

0 Kudos
rclarke2
Contributor
Contributor

Sounds like the script is running, but not collecting the right data. I'd investigate the logic of the script.

Maybe some command or module isn't being loaded if using an alternate user for the scheduled task?

Tags (1)
0 Kudos
glider777
Contributor
Contributor

If I just run the script from powershell it works fine.

0 Kudos
rclarke2
Contributor
Contributor

My actions for a scheduled task would be

 

Action: Start a program

Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe

Add Arguments (Optional):-Command c:\path\to\scriptyboy.ps1

 

edit: i am not a windows guy, sorry

 

0 Kudos