This is the simple script I am running:
#Script for reporting on VM information and Inventory.
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
---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:
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.
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"
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"