I am trying to set up a nightly refresh of a pool of VMs using a PS script and view CLI.
The script is set up and working. I can run it through powercli and have it refresh the pools manually.... Where im running into issues is when i try to run the script from the actual task.
here is the script
Connect-VIServer vCLIENT-vcenter1.SERVER.int $a = get-date ((get-date).AddMinutes(0)) -format "yyyy-MM-%d >HH:mm" Get-Pool -pool_id TEST | Get-DesktopVM | Send-LinkedCloneRefresh -schedule $a -forcelogoff $true -stoponerror $true
When i schedule the task i put the executable program as:
C:\Windows\system32\windowspowershell\v1.0\powershell.exe
Ive tired setting the paramaters to:
-noe -c ". \"D:\Program Files\VMware\VMware View\Server\extras\PowerShell\add-snapin.ps1\"" & C:\Scripts\Nightly.Refresh.ps1
But it times out in the scheduled tasks and hangs. I have to stop the task.
Does anyone know what the correct parameters should be?
Are you sure the task is running with the same credentials under the Task Sceduler ?
It could be that the execution policy used for the account under which the task runs in the scheduler is not set correctly.
Or that account can't do SSO to the vCenter.
Perhaps show us a screenshot of the Task Scheduler entry you created.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So the script was running before ?
It is running with the same account that you used to test the script ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
how do i set the account it runs with?
It only ran manually from within powershell cmd.
Found this
Is scheduled tasks no longer supported?
When you run it interactively from the PowerCLI is runs with the account you're logged on with.
And since you don't specify a user or credential on the Connect-VIServer, that will be the account used to connect to the vSphere server.
For a task in the Task Scheduler you can specify under which account it should run.
The account you specify should have a working PS environment and should be able to connect to the vSphere server and executes the cmdlets from the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That post is about PowerSHell v3.
Are you running PowerShell v3 ?
Officially the current PowerCLI version is not supported in PowerShell v3.
Try starting PowerShell with the '-version 2' option.
C:\Windows\system32\windowspowershell\v1.0\powershell.exe -version 2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Turns out my issue was because i schdeuled the task as a local admin and not as the domain admin.
Double check.. everything.