PowerShell Scirpt for Vsphere


To import the PowerShell modules for VMware from PSGallery

# To search for all vmware modules

Find-Module -name vmware.*


#Most important modules

Install-module -name vmware.powercli

install-module iname vmware.vim*


#Update the installed modules

Update-Module -name vmware.*


#Connect vCenter/ESXI in powershell

Connect-VIServer -server (vCenter, ESXI Name/IP)


#Get VM details (Name, powerstate, cpu, memory) on specific host 

Get-vmhost -name | Get-VM

#Check the VM powerON state

Get-vmhost -name | get-vm | Where-Object {$_.PowerState -eq "poweredON"}

# Command to check all VM deployed on VC or ESXI host


# Get  the  Snapshot created VM list 
Get-VM | Get-snapshot

# Get  the  Snapshot created VM list less than 60 days

# Get  the  Snapshot created VM list greater than 60 days

Get-VM | Get-snapshot | where {$_.CreateDate -gt(Get-Date).AddDays(-60)}

# Get cluster detail


# Get host details in cluster

Get-cluster | get-vmhost

Use below script to get host details inside the cluster.

Connect-VIServer -server
$cluster = Get-Cluster
$cluster | Get-VMHost

Command to Get list of the VMs inside the Cluster

 Get-cluster | Get-VM

No comments:

Post a Comment

Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is You need to connect your laptop and storage with...