VMware Cloud Community
ap_idb
Enthusiast
Enthusiast
Jump to solution

Monitor "VM Encryption" task through PowerCLI

I have a number of admins over the weekend which will be powering off VMs and applying our VMEncryption storage policy. I am not yet comfortable to create and distribute a script for this, but I want to create a script that will monitor and email the task PercentComplete. However, I cannot obtain the VM name from the get-task objects, I can only get the objectID and cannot seem to translate that easily.

Excerpt from my script:

$Report = get-task |

    Select-object Name,

    PercentComplete,

objectID

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, got it.

Try like this

Get-Task | 

   Select-object Name,

   @{N='VM';E={(Get-View -Id $_.ObjectId -Property Name).Name}},

  PercentComplete


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Are you using the VMware.VMEncryption module?

Mike has an accompanying post that describes the cmdlets in that module, and also how to monitor progress.

See PowerCLI for VM Encryption.

Did you check that out?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ap_idb
Enthusiast
Enthusiast
Jump to solution

Thanks for replying Luc.

Yes I am aware of the VMware Encryption Module, I've also spoken to Mike and have some scripts to report VM Encryption Status, as well as report on all the Key IDs to we can archive this. All good on the encryption front. Not using that Module on this script though.

As you're well aware, the time it takes to encrypt a VM can vary from minutes to hours. So, I essentially just want to monitor the "Reconfigure Virtual Machine" task and report back to the user what the % is at that time. This would give them a good feeling of how much longer it would take - they can go to the park with the kids, they should stick around as it might finish in the next 20 minutes, etc.

To do this, I have taken to PowerCLI to create a report of the running tasks and send via email then scheduling it to run every 15 minutes. My report is below, but I would like to essentially include the VM name so they're aware which task is running.

$Report = get-task |

    Select-object Name,

    PercentComplete,

     objectID

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, got it.

Try like this

Get-Task | 

   Select-object Name,

   @{N='VM';E={(Get-View -Id $_.ObjectId -Property Name).Name}},

  PercentComplete


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ap_idb
Enthusiast
Enthusiast
Jump to solution

Wow, simple enough. It shows the name twice oddly but it's more than usable, really appreciate it.

If you're up for it - What If I wanted to report only on Tasks named "ReconfigVM_Task" ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try like this

Get-Task | where{$_.Name -eq 'ReconfigVM_Task'} |

   Select-object Name,

   @{N='VM';E={(Get-View -Id $_.ObjectId -Property Name).Name}},

  PercentComplete

What do you mean by the name twice?
Two properties or  two values in the VM property?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ap_idb
Enthusiast
Enthusiast
Jump to solution

I'm embarrassed, I don't know why I overthought that. Thanks

Two Values in VM property:

snap.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you by any chance connected to multiple vCenters? Or using linked-mode?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ap_idb
Enthusiast
Enthusiast
Jump to solution

Yes, I am in linked mode. But I have not connected using –alllinked and this occurs if I connect to one vcenter or both.

0 Kudos
ap_idb
Enthusiast
Enthusiast
Jump to solution

In fact, I may have been connected prior. My script does the connections and I've done a disconnect from all viserver and now it displays just one per line.

Thanks again for all your help.

0 Kudos