Automation

 View Only
Expand all | Collapse all

Powercli : current tasks of pools and VMs in Horizon View

  • 1.  Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 09:36 AM

    Hello,

    Is it possible to see the current tasks of poolls and VMs in powercli in Horizon View?

    Thank You



  • 2.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 10:39 AM

    You should be able to get those via the Task_Get method on the Task service.



  • 3.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 10:57 AM

    sorry I do not understand, would you have an example? the get-task command is only for Vphere no?



  • 4.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 11:50 AM

    LucD​ This is horizon specific task.

    its shows pending horizon tasks, which is different then a vcenter task.



  • 5.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 11:51 AM

    My apologize I thought that was different, what Lucd gave was for horizon.



  • 6.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 11:52 AM

    I know, and I never mentioned Get-Task nor vSphere Tasks.
    The Task_Get method is from the Horizon View API, it is obviously not referring to the the same as vSphere Tasks, which you can query with the Get-Task cmdlet.



  • 7.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jan 21, 2021 04:41 PM

    Got a little confused trying to follow this thread, but *I think* you were about to answer the question I have.  I'm trying to list active tasks (as you pointed out in your screenshot) of all Horizon Pools. 

    We're using Horizon 7.11 & PowerCLI ver. 

    PowerCLI Version
    ----------------
    VMware PowerCLI 11.5.0 build 14912921
    ---------------
    Component Versions
    ---------------
    VMware Common PowerCLI Component 11.5 build 14898112
    VMware HorizonView PowerCLI Component 7.1.0 build 14653756
    VMware Cis Core PowerCLI Component PowerCLI Component 11.5 build 14898113
    VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.5 build 14899560

     

    Task_Get doesn't seem to work for me.  



  • 8.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jan 21, 2021 05:28 PM

    Below is the output I receive....

    PS C:\Windows\system32> $services1=$global:defaulthvservers.extensiondata

    PS C:\Windows\system32> $hvTask1 = $services1.Task.Task_Get()
    Cannot find an overload for "Task_Get" and the argument count: "0".
    At line:1 char:1
    + $hvTask1 = $services1.Task.Task_Get()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest



  • 9.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jan 21, 2021 04:41 PM

    Got a little confused trying to follow this thread, but *I think* you were about to answer the question I have.  I'm trying to list active tasks (as you pointed out in your screenshot) of all Horizon Pools. 

    We're using Horizon 7.11 & PowerCLI ver. 

    PowerCLI Version
    ----------------
    VMware PowerCLI 11.5.0 build 14912921
    ---------------
    Component Versions
    ---------------
    VMware Common PowerCLI Component 11.5 build 14898112
    VMware HorizonView PowerCLI Component 7.1.0 build 14653756
    VMware Cis Core PowerCLI Component PowerCLI Component 11.5 build 14898113
    VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.5 build 14899560

     

    Task_Get doesn't seem to work for me.  



  • 10.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 01:39 PM

    Try this, I'm not sure its correct, but maybe someone can fix it

    # Import the Horizon module

    Import-Module VMware.VimAutomation.HorizonView

    # Establish connection to Connection Server

    $hvServer = Connect-HVServer -server $hzConn -User $hzUser -Password $hzPass -Domain $hzDomain

    $ViewAPI = $hvServer.ExtensionData

    $query_service = New-Object "Vmware.Hv.QueryServiceService"

    $query = New-Object "Vmware.Hv.QueryDefinition"

    $query.queryEntityType = 'TaskInfo'

    $Tasks = $query_service.QueryService_Query($ViewAPI,$query)

    just replace $hzConn $hzUser $hzPass $hzDomain

    I'm assuming you want all the Tasks, and I'm not sure how task_get will help. That will help with a specific task, but not searching them. Looking at this for a refence

    Horizon View API – Query Service - The SLOG – SimonLong/Blog

    you are supposed to be able to use the query service to search for TaskInfo, which is what Task_Get returns. I can get the above code to work using the DesktopSummaryView object but not the TaskInfo one.



  • 11.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 02:00 PM

    Actually I read this more, since I wanted similar information. Tasks in the API reference the cloudpod architecture. TaskInfo which is what Task_Get returns has a catagory Type, and the only catagory types are

    "POD_FEDERATION_INITIALIZING"A task performing PodFederation initialize operation
    "POD_FEDERATION_UNINITIALIZING"A task performing PodFederation uninitialize operation
    "POD_FEDERATION_JOINING"A task performing PodFederation join operation
    "POD_FEDERATION_UNJOINING"A task performing PodFederation unjoin operation

    so Task_Get won't help in this case.



  • 12.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 01, 2018 02:56 PM

    Try this, I think this gets you want you want,

    # Import the Horizon module

    Import-Module VMware.VimAutomation.HorizonView

    # Establish connection to Connection Server

    $hvServer = Connect-HVServer -server $hzConn -User $hzUser -Password $hzPass -Domain $hzDomain

    $ViewAPI = $hvServer.ExtensionData

    $query_service = New-Object "Vmware.Hv.QueryServiceService"

    $query = New-Object "Vmware.Hv.QueryDefinition"

    $query.queryEntityType = 'MachineSummaryView'

    $machines = $query_service.QueryService_Query($ViewAPI,$query)

    $machineInfos=$ViewAPI.Machine.Machine_GetInfos($machineIds)

    foreach($machineInfo in $machineInfos)

    {

        if($machineInfo.ManagedMachineData.ViewComposerData.Operation -eq "PUSH_IMAGE")

        {

            Write-Host $machineInfo.Base.Name $machineInfo.ManagedMachineData.ViewComposerData.Operation $machineInfo.ManagedMachineData.ViewComposerData.OperationState $machineInfo.ManagedMachineData.ViewComposerData.BaseImagePath $machineInfo.ManagedMachineData.ViewComposerData.PendingBaseImageSnapshotPath

        }

    }

    It shows the desktop name, the maintenance task, what the state is, and the pending parent image, and the pending snapshot. The ones I had returned where the only ones that where showing up as pending tasks in horizon.



  • 13.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted May 04, 2018 07:31 AM

    Hello and thank you for your return.

    I think that it exceeds my competence, I thought to find a command type Get-HVtask ..... But no

    I will test your script thank you very much I come back to you after



  • 14.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jun 04, 2018 01:00 PM

    I couldn't get this working. Here is my output.

    Exception calling "Machine_GetInfos" with "1" argument(s): "ExceptionType : VMware.Hv.MethodFault

    ErrorMessage : Request missing value for required parameter 'ids' to method 'Machine_GetInfos'"

    At line:21 char:1

    + $machineInfos=$ViewAPI.Machine.Machine_GetInfos($machineIds)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException



  • 15.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 03, 2018 09:48 AM

    Its much easier indeed:

    $machines = Get-HVMachine -PoolName "YourPoolName"

    foreach($machine in $machines){

       $machine.ManagedMachineData.ViewComposerData.Operation

       $machine.ManagedMachineData.ViewComposerData.OperationState

       $machine.ManagedMachineData.InMaintenanceMode

    }

    Should give you the necessary informations.



  • 16.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 10, 2018 05:32 PM

    Thanks MartinE11. How would I accomplish this for Instant Clones? We aren't using a View Composer.



  • 17.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 11, 2018 03:30 PM

    Unfortunately I do not have the Instant Clone Feature licensed, so i can't really test it. But it should work as follows:

    $connectionServerName = "YourConnectionServerName"

    $machines = Get-HVMachine -PoolName "YourPoolName"


    $hvServer = Connect-HVServer -Server $connectionServerName -ErrorAction Stop

    $services = $hvServer.ExtensionData

    $desktop_helper = New-Object VMware.Hv.DesktopService

    foreach($machine in $machines){

       $desktopInfo = $desktop_helper.Desktop_Get($services,$machine.Base.Desktop)

       $desktopInfo.AutomatedDesktopData.ProvisioningStatusData.InstantCloneProvisioningStatusData.Operation

       $desktopInfo.AutomatedDesktopData.ProvisioningStatusData.InstantCloneProvisioningStatusData.instantClonePendingImageState

       $desktopInfo.AutomatedDesktopData.ProvisioningStatusData.InstantCloneProvisioningStatusData.instantCloneCurrentImageState

    }

    If you need any other Info, have a look at the API: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/e2e25628-4ed2-43fc-8bad-54fb86f3bb0f/8e4d2491-c740-4778-ac43-ba8f…



  • 18.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 11, 2018 05:05 PM

    This is EXACTLY what I was trying to accomplish. Thank you for all of your help!!



  • 19.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 16, 2018 07:40 AM

    No problem, glad I could help you.



  • 20.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 17, 2018 01:58 PM

    there's a query service that should be able to list all running tasks as well,



  • 21.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jul 17, 2018 02:00 PM

    oh and I added the get-hvtask to my project for the module. New functions vmware.hv.helper · GitHub



  • 22.  RE: Powercli : current tasks of pools and VMs in Horizon View

    Posted Jun 19, 2019 10:45 AM

    Hi,

    Thanks sjesse and MartinE11 for useful info  and scripts.

    But according to all available properties for MachineViewComposerData object there are still some missing data.

    It is primary Date/Time of scheduled task.

    Does anyone know where it is possible to find Date/Time of scheduled tasks?

    Thanks,

    Pavel