<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating new VM with async fails with &amp;quot;A task was canceled&amp;quot; in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959150#M111186</link>
    <description>&lt;P&gt;Some Tasks started through RunAsync are converted to so-called Client Side Tasks (vs Server Side Tasks).&lt;/P&gt;
&lt;P&gt;These Client Side Server tasks will show a different type of Task.&lt;BR /&gt;&lt;BR /&gt;Also, the &lt;A href="https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.common/commands/get-task/#default" target="_blank" rel="noopener"&gt;Get-Task&lt;/A&gt; cmdlet clearly states "&lt;EM&gt;The cmdlet retrieves information about the current or &lt;STRONG&gt;recent&lt;/STRONG&gt; tasks&lt;/EM&gt;"&lt;BR /&gt;That could be another reason why the Tasks shows as canceled, it is simply not there anymore (in the &lt;STRONG&gt;RecentTask&lt;/STRONG&gt; property in the &lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/97e6db01-d441-472e-ad53-b48c2bb0e1e4/45347fb1-052d-44b7-b3e9-cbefc34488e3/SDK/vsphere-ws/docs/ReferenceGuide/vim.TaskManager.html" target="_blank" rel="noopener"&gt;TaskManager&lt;/A&gt; object)&lt;BR /&gt;That was one of the reasons I wrote my Get-TaskPlus function in my&amp;nbsp;&lt;A href="https://www.lucd.info/2013/06/01/task-data-mining-an-improved-get-task/" target="_blank" rel="noopener"&gt;Task Data Mining – An improved Get-Task&lt;/A&gt; post.&lt;/P&gt;
&lt;P&gt;You might want to try that function, but be warned that it has issues with these Client Side Tasks.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 18:27:06 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2023-03-14T18:27:06Z</dc:date>
    <item>
      <title>Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959108#M111175</link>
      <description>&lt;P&gt;I am deploying a new VM from a content library OVA and it can take a while, so I am creating it with &lt;FONT face="andale mono,times"&gt;New-VM -RunAsync&lt;/FONT&gt; and then polling with &lt;FONT face="andale mono,times"&gt;Get-Task&lt;/FONT&gt; until it shows "Success" and then collecting the new VM with &lt;FONT face="andale mono,times"&gt;Wait-Task&lt;/FONT&gt;. However, sometimes the &lt;FONT face="andale mono,times"&gt;Wait-Task&lt;/FONT&gt; fails, returning &lt;FONT face="andale mono,times"&gt;$null&lt;/FONT&gt; and printing the error "A task was canceled", despite the vCenter task completing without issue.&lt;/P&gt;&lt;P&gt;My code is effectively:&lt;/P&gt;&lt;PRE&gt;$newvmtask = New-VM -RunAsync ...&lt;BR /&gt;do {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start-Sleep 15&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $taskstatus = Get-Task -Id $newvmtask.Uid&lt;BR /&gt;} while ($taskstatus.State -NE "Success")&lt;BR /&gt;$newvm = Wait-Task -Task $newvmtask&lt;/PRE&gt;&lt;P&gt;I've also tried it with the argument to &lt;FONT face="andale mono,times"&gt;Wait-Task&lt;/FONT&gt; as &lt;FONT face="andale mono,times"&gt;$taskstatus&lt;/FONT&gt; instead, but it produces the same problem.&lt;/P&gt;&lt;P&gt;Again, the problem is intermittent. It seems to coincide with the task completion taking over 5 minutes, which makes it feel like some sort of timeout. In fact, when I run &lt;FONT face="andale mono,times"&gt;New-VM&lt;/FONT&gt; without &lt;FONT face="andale mono,times"&gt;-RunAsync&lt;/FONT&gt; and it takes more than 5 minutes, I get the same error exactly 5 minutes after the cmdlet was submitted. But you'd think that using &lt;FONT face="andale mono,times"&gt;-RunAsync&lt;/FONT&gt; and polling would avoid that problem.&lt;/P&gt;&lt;P&gt;I'm having trouble consistently reproducing the problem, but in automated tasks it happens around half the time.&lt;/P&gt;&lt;P&gt;I have tried adjusting the client timeout with &lt;FONT face="andale mono,times"&gt;Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds 600&lt;/FONT&gt; to extend the timeout to 10 minutes, but it doesn't seem to help.&lt;/P&gt;&lt;P&gt;This is running PowerCLI 13.0.0 under PowerShell 7.3.2 on Linux: CentOS 7.9.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:53:54 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959108#M111175</guid>
      <dc:creator>wfaulk_bw</dc:creator>
      <dc:date>2023-03-14T15:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959130#M111180</link>
      <description>&lt;P&gt;Does&amp;nbsp;&lt;STRONG&gt;$newvmtask.GetType()&lt;/STRONG&gt; return a name like&amp;nbsp;&lt;STRONG&gt;ClientSideTaskImpl&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:06:01 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959130#M111180</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-03-14T17:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959145#M111183</link>
      <description>&lt;P&gt;In the data I posted above, I just noticed that the timestamps are weird.&lt;/P&gt;&lt;P&gt;The task there says it ran from 5:10:39 to 5:15:39, which is exactly 5m. On vSphere, the matching task says it ran from 5:10:40 to 5:15:53. So the PowerCLI task claims that it finished earlier than vCenter says it finished, by 14 seconds.&lt;/P&gt;&lt;P&gt;So there's a 5 minute timeout that causes the task to report "Success"? You'd think a timeout there would at least report a failure.&lt;/P&gt;&lt;P&gt;But if the results from Get-Task are wrong, Wait-Task should still just block until the task is completed. So it feels like there's a timeout that's shared between Get-Task and Wait-Task.&lt;/P&gt;&lt;P&gt;I'm seeing some old &lt;A href="https://github.com/dotnet/runtime/issues/24392" target="_blank" rel="noopener"&gt;bug reports about a shared HTTP handler under PowerShell in Linux&lt;/A&gt;. I wonder if that could be relevant.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:18:41 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959145#M111183</guid>
      <dc:creator>wfaulk_bw</dc:creator>
      <dc:date>2023-03-14T18:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959150#M111186</link>
      <description>&lt;P&gt;Some Tasks started through RunAsync are converted to so-called Client Side Tasks (vs Server Side Tasks).&lt;/P&gt;
&lt;P&gt;These Client Side Server tasks will show a different type of Task.&lt;BR /&gt;&lt;BR /&gt;Also, the &lt;A href="https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.common/commands/get-task/#default" target="_blank" rel="noopener"&gt;Get-Task&lt;/A&gt; cmdlet clearly states "&lt;EM&gt;The cmdlet retrieves information about the current or &lt;STRONG&gt;recent&lt;/STRONG&gt; tasks&lt;/EM&gt;"&lt;BR /&gt;That could be another reason why the Tasks shows as canceled, it is simply not there anymore (in the &lt;STRONG&gt;RecentTask&lt;/STRONG&gt; property in the &lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/97e6db01-d441-472e-ad53-b48c2bb0e1e4/45347fb1-052d-44b7-b3e9-cbefc34488e3/SDK/vsphere-ws/docs/ReferenceGuide/vim.TaskManager.html" target="_blank" rel="noopener"&gt;TaskManager&lt;/A&gt; object)&lt;BR /&gt;That was one of the reasons I wrote my Get-TaskPlus function in my&amp;nbsp;&lt;A href="https://www.lucd.info/2013/06/01/task-data-mining-an-improved-get-task/" target="_blank" rel="noopener"&gt;Task Data Mining – An improved Get-Task&lt;/A&gt; post.&lt;/P&gt;
&lt;P&gt;You might want to try that function, but be warned that it has issues with these Client Side Tasks.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:27:06 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959150#M111186</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-03-14T18:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959157#M111190</link>
      <description>&lt;P&gt;I ran my test again and ran Get-Task without arguments after getting back "Success" on the specific task.&lt;/P&gt;&lt;P&gt;The relevant tasks are definitely still in the list.&lt;/P&gt;&lt;PRE&gt;Description                                              StartTime            FinishTime             State
-----------                                              ---------            ----------             -----
                                                         3/14/2023 6:49:02 PM 3/14/2023 6:53:40 PM Success
Deploy OVF template                                      3/14/2023 6:48:50 PM                      Running
Deploy OVF package from Content Library to Resource Pool 3/14/2023 6:48:44 PM                      Running
Delete virtual machine                                   3/14/2023 6:44:05 PM 3/14/2023 6:44:05 PM Success
Fetch Content of a Library Item                          3/14/2023 6:48:39 PM 3/14/2023 6:48:41 PM Success
Parse OVF package in Content Library                     3/14/2023 6:48:38 PM 3/14/2023 6:48:44 PM Success
Fetch Content of a Library Item                          3/14/2023 6:48:44 PM 3/14/2023 6:48:46 PM Success
Fetch Content of a Library Item                          3/14/2023 6:49:00 PM 3/14/2023 6:49:01 PM Success&lt;/PRE&gt;&lt;P&gt;In the full Task Console in the vCenter web UI, there are only four tasks that were a result of this New-VM, and they're all shown here: the "Parse OVF package…", "Deploy OVF package…", "Deploy OVF template", and "Transfer File(s)" tasks, the last of which is the one that has no description in this list. (Its "Name" is "NfcCopy_Task".)&lt;/P&gt;&lt;P&gt;So I don't think that it's a case of the tasks falling off the "recent" list.&lt;/P&gt;&lt;P&gt;Can you think of a reason that this would fail other than that the cmdlet is broken? I really want to open a VMware support case about this, but they're giving me a hard time about needing to purchase SDK support, but this feels very much like "&lt;A href="https://developer.vmware.com/docs/15315/powercli-user-s-guide/GUID-0F835722-E667-4177-A8EF-51AB15FA837E.html" target="_blank" rel="noopener"&gt;Cmdlets are not working as documented&lt;/A&gt;".&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 19:17:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959157#M111190</guid>
      <dc:creator>wfaulk_bw</dc:creator>
      <dc:date>2023-03-14T19:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959158#M111191</link>
      <description>&lt;P&gt;No clue why Get-Task would fail.&lt;BR /&gt;I always use my Get-TaskPlus function.&lt;BR /&gt;&lt;BR /&gt;GSS is wrong, you don't need an SDK Support contract.&lt;BR /&gt;See also&amp;nbsp;&lt;A href="https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Copy-VMGuestFile-fails-with-error-500-when-Guest-OS-is-quot/m-p/2897749/highlight/true#M105644" target="_blank"&gt;Solved: Re: Copy-VMGuestFile fails with error 500 when Gue... - VMware Technology Network VMTN&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 19:21:18 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959158#M111191</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-03-14T19:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959175#M111192</link>
      <description>&lt;P&gt;I don't even understand how I would use your Get-TaskPlus. I have a specific task that was returned by New-VM -RunAsync. There doesn't seem to be a way to tell Get-TaskPlus about that specific task. (Ignoring, as you point out, the fact that it seems to be some virtual local task instead of any actual task on the vCenter server.) If I have to resort to searching for the task, I might as well just search for the VM.&lt;/P&gt;&lt;P&gt;Thanks for your help, though. I at least feel like I'm not being dense and just totally using it wrong.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 21:54:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959175#M111192</guid>
      <dc:creator>wfaulk_bw</dc:creator>
      <dc:date>2023-03-14T21:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new VM with async fails with "A task was canceled"</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959824#M111258</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;I'm not sure this will help. But in my scripts I use something like this:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;$New_Vm_Task = New-VM -ContentLibraryItem $VmTemplate -Name $VMName -ResourcePool $ResourcePool -Location $Location -StorageFormat $DiskFormat -Datastore $Datastore -RunAsync
Wait-Event -Timeout 20
$task = Get-Task -Status Running | where name -eq 'Deploy OVF template' | where {$_.ExtensionData.Info.EntityName -eq "$VMName"} 
if ($task) {
    $ts = Wait-Task -Task $task
}
elseif (!$task) {
    Wait-Event -Timeout 18
    $task = Get-Task -Status Running | where name -eq 'Deploy OVF template' | where {$_.ExtensionData.Info.EntityName -eq "$VMName"}
    $ts = Wait-Task -Task $task 
    if (!$task) {
        Wait-Task -Task $New_Vm_Task 
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 12:41:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Creating-new-VM-with-async-fails-with-quot-A-task-was-canceled/m-p/2959824#M111258</guid>
      <dc:creator>Macleud</dc:creator>
      <dc:date>2023-03-18T12:41:10Z</dc:date>
    </item>
  </channel>
</rss>

