robc_yk
Enthusiast
Enthusiast

PowerCLI script runs locally, but not under scheduled task in Windows 2008 R2

This is the simple script I am running:

---Begin Script---

#Script for reporting on VM information and Inventory.
add-pssnapin VMware.VimAutomation.Core

Connect-VIServer -Server VCENTESERVERNAME.Domain

Get-VM | select Name, Notes, Folder, PowerState, Version, NumCpu, MemoryGB, UsedSpaceGB, ProvisionedSpaceGB | sort Notes | Export-Csv -path "C:\_VMware_Scripts\vminventory_$((Get-Date).ToString('MM-dd-yyyy')).csv" -NoTypeInformation

---End Script---

---Begin Scheduled Task---

The script runs in the local PowerCLI console but when scheduling it there are no results.

the windows task scheduler is set as:

Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add Arguments: -PSConsoleFile “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" “& ‘C:\_VMware_Scripts\GetVMInventory.ps1′”

---End Scheduled Task---

The scheduled task fails with (0xFFFC0000)

The account it is using is the same domain account that runs the script locally.

It is running from the local vsphere console install server.

I have tried all things I could find.

Any help greatly appreciated.

Thank You.

4 Replies
LucD
Leadership
Leadership

Did you already try switching off verbose messages ?

You can do

$VerbosePreference = 'SilentlyContinue'


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

0 Kudos
TrevorBlack
Enthusiast
Enthusiast

I had trouble getting mine to run as scheduled tasks as well. Here's what I wound up doing.

I actually pointed the scheduled task to a CMD file without using anything in the arguments box. So, for me the schedule task just points to C:\PowerCLI\ScriptName.cmd

Then, the contents of the CMD are as follows:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "&" "C:\PowerCLI\ScriptFile.ps1"

esxi1979
Expert
Expert

i tried identical .. no luck

i have a windows 7 os

0 Kudos
TrevorBlack
Enthusiast
Enthusiast

You can try outputting to a log file to determine the issue.

Change the CMD file contents to (obviously adjusting paths/filenames where appropriate):

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "&" "C:\PowerCLI\ScriptFile.ps1 -verbose >> C:\PowerCLI\OutputLog.log 2>&1"

0 Kudos