alanrenouf / vCheck-vSphere

vCheck Daily Report for vSphere
MIT License
735 stars 326 forks source link

Scheduled Task #195

Closed matthewlroth closed 10 years ago

matthewlroth commented 10 years ago

having a weird issue with running a scheduled task. When i run from a command line, everything is happy and completes. output is saved and email is sent

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

when i create the scheduled task

Program: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

args: -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

it just runs and never completes. if i manually end the task it sends the email. I decided to redirect the output to a txt file using >> "c:\temp\log.txt". running from command line i get the needed output

if i run that same command as a scheduled task there is no output to the log.

any help would be greatly appreciated on getting the scheduled task to work properly.

randy16randy commented 10 years ago

Here are the settings I have from my scheduled vCheck task

GENERAL

TRIGGERS

ACTIONS

Only differences I see from yours other than how you log is have the ampersand and single quotes used as well. It was over a year ago that I did it so I don’t remember exactly what led me to the above but I do remember having similar difficulties on initial setup.

-Randy-

From: matthewlroth [mailto:notifications@github.com] Sent: Wed, April 23, 2014 1:34 PM To: alanrenouf/vCheck-vSphere Subject: [vCheck-vSphere] Scheduled Task (#195)

having a weird issue with running a scheduled task. When i run from a command line, everything is happen and completes

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

when i create the scheduled task

Program: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

args: -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

it just runs and never completes. if i manually end the task it sends the email. I decided to redirect the output to a txt file using >> "c:\temp\log.txt". running from command line i get the needed output

if i run that same command as a scheduled task there is no output to the log.

any help would be greatly appreciated on getting the scheduled task to work properly.

— Reply to this email directly or view it on GitHubhttps://github.com/alanrenouf/vCheck-vSphere/issues/195.

smasterson commented 10 years ago

I take a much simpler approach (though is most likely not perfect for everyone)

The powershell executable folder is already added to PATH so the full path is not necessary (YMMV). The script will dynamically load PowerCli so no need to add that to the mix either.

Program: powershell

Arguments: -file E:\vCheck\vCheck.ps1 -OutputPath \sharepoint\reports\vCheck

Hope this helps

--shawn

On Wed, Apr 23, 2014 at 3:50 PM, Randy notifications@github.com wrote:

Here are the settings I have from my scheduled vCheck task

GENERAL

  • Run whether user logged on or not
  • Run with highest privileges
  • Configure for Windows 7, Server 2008-R2

TRIGGERS

  • Daily at 6 am

ACTIONS

  • Action = Start a program
  • Program/Script = C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
  • Argument = -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\vCheck\vCheck.ps1'"

Only differences I see from yours other than how you log is have the ampersand and single quotes used as well. It was over a year ago that I did it so I don’t remember exactly what led me to the above but I do remember having similar difficulties on initial setup.

-Randy-

From: matthewlroth [mailto:notifications@github.com] Sent: Wed, April 23, 2014 1:34 PM To: alanrenouf/vCheck-vSphere Subject: [vCheck-vSphere] Scheduled Task (#195)

having a weird issue with running a scheduled task. When i run from a command line, everything is happen and completes

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

when i create the scheduled task

Program: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

args: -psc "D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noexit "D:\vCheck-vSphere-master\vcheck.ps1" -outputpath "c:\temp"

it just runs and never completes. if i manually end the task it sends the email. I decided to redirect the output to a txt file using >> "c:\temp\log.txt". running from command line i get the needed output

if i run that same command as a scheduled task there is no output to the log.

any help would be greatly appreciated on getting the scheduled task to work properly.

— Reply to this email directly or view it on GitHub< https://github.com/alanrenouf/vCheck-vSphere/issues/195>.

— Reply to this email directly or view it on GitHubhttps://github.com/alanrenouf/vCheck-vSphere/issues/195#issuecomment-41206263 .

matthewlroth commented 10 years ago

thanks randy worked like a charm.

Mike-Rophone commented 10 years ago

Is there any way to set up vCheck to run as the local SYSTEM account in Task Scheduler? Whenever I try to use the SYSTEM account, the report comes back blank. We have lockdowns in place which prevent storing username/password information.

Any help is appreciated!

randy16randy commented 10 years ago

Sorry, I haven’t set mine up that way so don’t know.

From: Mike-Rophone [mailto:notifications@github.com] Sent: Thu, April 24, 2014 3:50 PM To: alanrenouf/vCheck-vSphere Cc: Randy Redekopp Subject: Re: [vCheck-vSphere] Scheduled Task (#195)

Is there any way to set up vCheck to run as the local SYSTEM account in Task Scheduler? Whenever I try to use the SYSTEM account, the report comes back blank. We have lockdowns in place which prevent storing username/password information.

Any help is appreciated!

— Reply to this email directly or view it on GitHubhttps://github.com/alanrenouf/vCheck-vSphere/issues/195#issuecomment-41337014.

Sneddo commented 10 years ago

@Mike-Rophone Either way, you would be storing a password (i.e. as the scheduled task and use passthrough authentication to vCenter, or save the vCenter login details in a script.

The second option is not actually supported in vCheck at the moment (despite it looking for a credential file).

Next time ask a question in a new issue rather than hijacking another one. Thanks