Monday , April 23 2018

Vmware PowerCli Cheat Sheet – Daily Administration

NOTE _ Use powercli with proper understanding.For Example Get-vm | Set-VM , Pipeline Retrieves all the VMs and Applies to all vms.

Connecting to Vcenter –  ( Passes Credentials in Plain Text)

Two ways – One liner if your password doesn’t contain contradicting letters with powercli like $.

Connect-VIServer -Server -Protocol https -User "care\manoharan" -Password Welcome..@01234


or Store cred to Variable and pass it. (Passes Credential Securely)

$cred = Get-Credential

Enter UPN –

Enter Password – Welcome..@01234

Connect-VIServer -Server -Protocol https -credential $cred

Loading ISO –

Get-VM “VMNAME” | Get-CDDrive | Set-cddrive -ISOPath "[DATASTORE-OS] ISOs/Win2012R2.iso" -StartConnected $true

Unloading ISO –

Get-VM “VMNAME” | Get-CDDrive | Set-CDDrive -NoMedia

To See How Machines have loaded with ISOs Unnecessarily –

Get-VM | Get-CDDrive | where-object{$_.isopath -notlike $null} | FT Parent,Isopath –AutoSize


Adding Notes to Mulitple Virtual Machines using CSV –

CSV looks like below


Import-Csv vms.csv | ForEach-Object{Set-VM $_.Name -Notes $_.Description -Confirm:$false}

To Check SSH and Esxi Shell Status –

Get-VMHost 10.* | Get-VMHostService | Where-Object {$_.Key -like "TSM*"}

TSM-SSH – Denotes Esxi SSH

TSM – – Denotes Esxi Shell


To Set – Without Confirmation – Add End of the command –     -Confirm:$false

Enabling SSH And Shell –

Get-VMHost 10.* | Get-VMHostService | Where-Object {$_.Key -like "TSM*"}| Set-VMHostService -policy "on"

Restarting VMHostService on Esxi for SSH and Shell to refresh

Get-VMHost 10.* | Get-VMHostService | Where-Object {$_.Key -like "TSM*"}| Restart-VMHostService

Disabling IPv6 without logging into Esxi

login to Esxi using putty.

esxcli system module parameters set -m tcpip4 -p ipv6=0


Disabling ipv6 – requires reboot

Get-VMHost "VMHostname" | Restart-VMHost

Assigning TAGS –

Name Category Description
Low WindowsUpdates Servers can be Rebooted any time for Maintenance – Normal Change Process
Medium WindowsUpdates Servers can be Rebooted agreeing with the owner – Normal Change Process
High WindowsUpdates Servers can be Rebooted only with Scheduled Change – Critical Change Process 
Team1 Ownership ServiceDesk Team
Team2 Ownership Architects Team
Team3 Ownership Network Team

Two Categories –

  • Ownership
  • WindowsUpdates

Each Categories have Tags. VMs can have only one tag from each category. Team1 = can be NetworkTeam

Getting Tag of a Virtual Machine – or use Web Client to manage tags using GUI

Get-VM VMName | Get-TagAssignment


Assigning Tags to VMs –

Get-VM VMName | New-TagAssignment –Tag (get-tag “tagname”)

To see Tags from Each Category –

Get-VM VMName | Get-TagAssignment -Category Windowsupdates

To Remove a Tags from a VM – Specific Category –

Get-VM VMName | Get-TagAssignment -Category Windowsupdates | Remove-TagAssignment


Get UUID for a Specific VMHost – (Used for Red hat licensing Servers -Satellite servers) 

(Get-VMHost | Get-View).hardware.systeminfo.uuid


Now to Export my Data –

If you name the Categories like I did. My script will work or modify Ownership =,Windowsupdates =  lines in the script.


Write-host "Saving CSV Variable"
$ExportPath = "Vms.csv"
Write-host "Saved CSV Variable"
Write-host "Saving ALL VMs"
$VMs = Get-VM
Write-host "Saved ALL VMs"
$VCenter = @()
Write-host "Entering Loop"
foreach ($vm in $VMs)
Write-host "Collecting $VM info"
$HostServer = $vm.vmhost.Name
$VMSysInfo = Get-VMGuest -VM $VM
$MyObject = New-Object PSObject -Property @{
VMName = $
VMHostName = $VMSysInfo.HostName
VMIP = $VMSysInfo.IPAddress
VMInstalledOS = $VMSysInfo.OSFullName
PowerState = $vm.powerstate
HostServer = $HostServer
HostCluster = (Get-Cluster -VMHost $HostServer).Name
Notes = $vm.notes
Ownership = ($vm | Get-TagAssignment | Where-Object {$_.Tag -like "Ownership/*"})
Windowsupdates = ($vm | Get-TagAssignment | Where-Object {$_.Tag -like "Windowsupdates/*"})
$VCenter += $MyObject
$VCenter |
Select VMName,
@{N='VMIPAddress';E={$_.VMIP -join '; '}},
Windowsupdates |
Export-Csv $ExportPath –NoTypeInformation

Helpful report – VMWare Esxi Compliance Report – To check ipv6,hostinfo,ssh,shell status etc.

About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Exchange Server MVP , Publisher of
Supporting/Deploying/Designing Microsoft Exchange for some years.
Extensive experience on Microsoft Technologies.

Check Also

Installation can’t proceed until all Exchange 2003 Servers are removed

Had to extend schema before installing Exchange 2016 on a Exchange 2010 Server environment. Eventually ...


  1. Myfirstname Mylastname VII

    Great Article, Thank you! In its present form connecting to VI Server or host with this PowerShell code could present a security risk since it passes in clear text as you depicted. I would suggest revamping the PS code to something more elegant:

    PS > Connect-VIServer -Credential (Get-Credential)

    This will pop up a login box where to supply your credentials.

    Just a thought. =0)

    • Satheshwaran Manoharan

      True. Yes. thanks for the thought.

      In my case – I always use the jump server within the secure network.

      Updated the post .

Leave a Reply

Your email address will not be published.