VMware Cloud Community
spunkybd
Contributor
Contributor

NEed some help with pool refresh scheduled task using powercli

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?

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

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

Reply
0 Kudos
spunkybd
Contributor
Contributor

Here is a screen shot... started a while ago.. just hangs and no task created.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
spunkybd
Contributor
Contributor

how do i set the account it runs with?

It only ran manually from within powershell cmd.

Reply
0 Kudos
spunkybd
Contributor
Contributor

Reply
0 Kudos
LucD
Leadership
Leadership

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.

schtask.png

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

LucD
Leadership
Leadership

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

spunkybd
Contributor
Contributor

Turns out my issue was because i schdeuled the task as a local admin and not as the domain admin.

Double check.. everything.

Reply
0 Kudos