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 192.168.1.51 (vCenter, ESXI Name/IP)

====================================

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

Get-vmhost -name 192.168.1.102 | Get-VM


=======================================================
#Check the VM powerON state

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


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

Get-VM


=============================================
# 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-cluster

# Get host details in cluster

Get-cluster | get-vmhost

Use below script to get host details inside the cluster.

Connect-VIServer -server 192.168.1.53
Get-cluster
$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 10.0.0.1/2 You need to connect your laptop and storage with...