VMware VM created and deleted list by users using PowerCLI

How to check quickly in VMware vCenter about users who have created or deleted the VMs?

The below PowerCLI script can be fetched using the TaskEvent which has the description VmBeingDeployedEvent or VmBeingClonedEvent and VmRemovedEvent in VMware vCenter 6.

VMware PowerCLI

VMware PowerCLI ConnectConnect your vCenter

> Connect-VIServer vcenter.cloudkb.com

Name Port User 
---- ---- ---- 
vcenter.cloudkb.com 443 VSPHERE.LOCAL\Administrator

 

You can list the virtual machine details which user has removed or deleted and Created, check the vCenter Server Events Logs using PowerCLI command to list all the details.

Use the following powerCLI command to list VM created list.

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-30) | where {$_.Gettype().Name -eq “VmCreatedEvent” -or $_.Gettype().Name -eq “VmBeingClonedEvent” -or $_.Gettype().Name -eq “VmBeingDeployedEvent”} | %{“{0} created by {1}” -f $_.VM.Name,$_.UserName}

Use the following PowerCLI command to list last 7 days VM deleted Event logs with a username.

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-7) | where {$_.Gettype().Name -eq “VmRemovedEvent”} | %{“{0} created by {1}” -f $_.VM.Name,$_.UserName}

How to get a list Virtual Machine Snapshots in VMware

This is additional information to get a list of all VM Snapshots for VMs managed by vCenter you can type the following command using PowerCLI.

get-vm | get-snapshot | format-list

The command above will give you the following properties:

Description
Created
Quiesced
PowerState
VM
VMId
Parent
ParentSnapshotId
ParentSnapshot
Children
SizeMB
IsCurrent
IsReplaySupported
ExtensionData
Id
Name
Uid

If you want the VM list with the name of the snapshot, you could simply add these properties after “format-list” as shown below.

get-vm | get-snapshot | format-list vm,name

 

 

How to enable nested virtualization on Google Cloud

Google Cloud supports nested virtualization using the KVM hypervisor on Linux instances. This nested virtualization feature allows you to run one or more virtual machines inside a Linux virtual machine by leveraging Intel VT-x processor, It means VMs inside of VMs. The only requirement is that the VM has to run on an Intel Haswell or newer CPU. Here are the steps, how to enable nested virtualization on google cloud.

  • ESX and Xen hypervisors are not supported.
  • Nested virtualization does not currently support Windows instances.

Google has verified nested virtualization tests which work perfectly using the following Linux distros. The list of available regions and zones for the CPU platforms available in each zone.

– CentOS 7 with kernel version 3.10
– Debian 9 with kernel version 4.9
– Debian 8 with kernel version 3.16
– RHEL 7 with kernel version 3.10
– SLES 12.2 with kernel version 4.4
– SLES 12.1 with kernel version 3.12
– Ubuntu 16.04 LTS with kernel version 4.4
– Ubuntu 14.04 LTS with kernel version 3.13

How to Enable nested virtualization on Google Cloud

You can enable nested virtualization using ‘gcloud’ command-line tool or the API. It would be required to create a custom image with the special license key required for virtualization. We have created a new nested virtualization image using an existing image as a source image.

Log in your Google Cloud Console

Click top right corner - > Activate Google Cloud Shell
google cloud shell

GCP shell

List all compute images including deprecated.

$ gcloud compute images list --show-deprecated
gcloud list images

gcloud list images

You can use any one of the image as the source image to enable nested virtualization.

Syntax,

$ gcloud compute images create <nested_image_name> \
--source-image=<os_image_name> --source-image-project=<source_image_project> \
--licenses="https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"

For example, the following command creates an image named ‘gcp-nested-vm-image‘ from an existing centos image named ‘centos-7-v20170719‘.

$ gcloud compute images create gcp-nested-vm-image \
--source-image=centos-7-v20170719 --source-image-project=centos-cloud \
--licenses="https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"

Once done. Create a VM instance with the custom image in a zone that supports Haswell or higher.

Using the Console.

Login Compute Engine -> VM instances -> CREATE INSTANCE

Using gcloud command.

$ gcloud compute instances create example-nested-vm --zone us-central1-b \
--image gcp-nested-vm-image

Once VM created, connect the VM SSH and check that nested virtualization is enabled by running the following command.

# grep -cw vmx /proc/cpuinfo

or

# cat /proc/cpuinfo | grep vmx

A non-zero response confirms that nested virtualization is enabled.

You have enabeld the nested virtualization on your google cloud. Now you can start a nested VM in many different ways like qemu-kvm installation.

 

 

ESXi adding datastore Error Stack Call “HostDatastoreSystem.QueryVmfsDatastoreCreateOptions”

Most of the datacenter has given the hosts which already used and properly not cleaned to the new customers. Please note this whenever you are going to dismantle any storage, make sure you properly cleaned before given to server providers. The following error we received while we create a datastore for the new ESXi host in vSphere client.

Error:Cannot change the host configuration. Error Stack Call “HostDatastoreSystem.QueryVmfsDatastoreCreateOptions” for object “ha-datastoresystem”

There are various situations which might lead to pre-existing info on the disk. It was an issue with pre-existing or incompatible information on the hard disks. when you try to re-purpose existing storage devices is ensuring that all data and existing partitions have been completely removed.

ESXi adding datastore errors

ESXi adding datastore Error

This issue has resolved in ESXi using partedUtil tool, you need to run the following command for each disk that you’re having issues.

NOTE: This will ERASE ALL DATA on the disk in question so be careful to select the right disks!

List all the existing devices

[root@localhost:~] /usr/lib/vmware/vm-support/bin/smartinfo.sh

To get each device information.

[root@localhost:~] esxcli storage core device smart get -d <device-id>

Run partedUtil command to fix Error:Cannot change the host configuration. Error Stack Call “HostDatastoreSystem.QueryVmfsDatastoreCreateOptions” for object “ha-datastoresystem”

[root@localhost:~] partedUtil mklabel /dev/disks/<disk id> msdos

 

Example,

[root@localhost:~] /usr/lib/vmware/vm-support/bin/smartinfo.sh
SMART Information for disks.

Device: t10.ATA_____WDC_WD1003FAYX2D01Y7B1________________________WD2DWCAE35326661
Parameter Value Threshold Worst
-----------------------------------------------------
Health Status OK N/A N/A
Media Wearout Indicator N/A N/A N/A
Write Error Count N/A N/A N/A
Read Error Count 200 51 200
Power-on Hours 42 0 42
Power Cycle Count 100 0 100
Reallocated Sector Count 200 140 200
Raw Read Error Rate 200 51 200
Drive Temperature 114 0 107
Driver Rated Max Temperature N/A N/A N/A
Write Sectors TOT Count 200 0 200
Read Sectors TOT Count 200 0 200
Initial Bad Block Count N/A N/A N/A
[root@localhost:~] partedUtil mklabel /dev/disks/t10.ATA_____WDC_WD1003FAYX2D01Y7B1________________________WD2DWCAE35326661 msdos

You have done. Add new datastore via the vSphere Client or vCenter Storage -> Add Storage.

This is also can be done via the vSphere Web Client, vCenter has introduced in vSphere 6.0 Update 1 to help assist with this procedure.

You can find this new option (icon with disk and eraser) by clicking onto a specific ESXi host and then select the Manage->Storage Adapters and then be highlighting the specific storage device you wish to erase as seen in the screenshot below.

Before proceeding to erase any disk, review twice that is the correct disk.

Fix vCenter storage errors

vCenter storage errors

Once you have finished you can go back to the vSphere client and add the disks successfully, no reboots required.