In this some examples of PowerCLI commands I frequently use during my work.

Bypass PowerCLI security warnings “Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run –.ps1? [D] Do not run [R] Run once

Set-ExecutionPolicy bypass

Update the PowerCLI modules

Update-Module -Name VMware.PowerCLI

Import all the PowerCLI VMware modules

Get-module -ListAvailable VMware* | Import-Module

Connect to vCenter or ESX host by using an encrypted password

New-VICredentialStoreItem -Host <servername> -Password PASSWORD -User <username> -file C:\"PowerCLI\vicredentials.xml"

Connect to vCenter by using the XML file

$creds = Get-VICredentialStoreItem -file C:\"PowerCLI\vicredentials.xml"
Connect-VIServer -Server $creds.Host -user $creds.User -password $creds.Password

Put an ESXi host in maintenance mode

Connect-Viserver <server>
Get-VMHost -Name <host> | set-vmhost -State Maintenance

Enable SSH for all ESXi hosts

Get-Cluster | Get-VMhost | Get-VMHostService | Where-Object { $_.Key -eq “TSM-SSH”} | Start-VMHostService -Confirm:$false

Disable SSH for all ESXi hosts

Get-Cluster | Get-VMhost | Get-VMHostService | Where-Object { $_.Key -eq “TSM-SSH”} | Stop-VMHostService -Confirm:$false

Running a schedule task

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "&amp; 'C:\PowerCLI\snapshot.ps1'"

Change root password VMware ESX(i) host

Connect-VIserver servername
Set-VMHostAccount -UserAccount root -Password Password

Change multipath policy to RoundRobin for alle the datastores that matches the

Get-vmhost servername | Get-ScsiLun -CanonicalName 'naa.6000eb*' | Set-ScsiLun -MultipathPolicy "RoundRobin"

HP LeftHand = naa.6000*
HP 3PAR = naa.60002ac*
HP EVA = naa.6001*
NetApp = naa.60a9*

Update VMware tools VM

get-vm VNNAME | update-tools

Get the total amount of vRAM used by the powered on VMs

Get-VM | where {$_.PowerState -eq "PoweredOn"} | Measure-Object -Property MemoryMB -Sum



Test vSAN Performance

Test-VsanStoragePerformance -Cluster $cluster -TestDurationsSeconds 120 -StoragePolicy $policy -WorkLoad BasicSanityTest

3 thoughts on “POWERCLI

  1. Hey Ivo!

    Voor het script Change multipath policy to RoundRobin for HP LeftHand (naa.6000eb*) datastores:
    Werkt geweldig, alleen ik denk dat naa.6001* geldt denk ik voor een HP EVA 4400 (?), maar bij een HP EVA 4000 is het naa.6005*.

    Ter info, thnx voor je script!

  2. I am looking for a way to pull all the NIC details from all our our VMs. For instance, I need to gather foe following info:
    Server Name
    NIC Name
    Link Speed
    TCP Offloaded

    Can you help me with a script to gather this info?

    Thank you!

  3. Hello – I am trying to write the output of the AMS versions to csv and it’s not liking it for some reason. When I first ran the script you published, I did get an error where I had to remove the ‘FT’ from the script, and I see the results displayed perfectly. I just need to export to csv – can you help? Here is what I have:

    #Connect to vCenter
    $creds = Get-VICredentialStoreItem -file c:\creds\mycreds.xml
    connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password

    $GetHosts = Get-VMHost -Location ‘My Cluster’

    ForEach ($VMHost in $GetHosts) {

    $ESXCLI = Get-EsxCli -VMHost $VMHost

    #Write-Host $VMHost -ForegroundColor Green

    $ESXCLI.software.vib.list() | Where {$_.Name -eq “hp-ams”} | Select Name,Vendor,Version | export-csv c:\ams.csv

    # Disconnect session vCenter

    Disconnect-VIserver -Confirm:$false

Leave a Comment