2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator

PowerShell PowerCLI Start Here

PowerCLI is a VMware toolset that adds a set of PowerShell Cmdlets to PowerShell via a module that provide scripting access to ESXI and vCenter. You can use this to configure ESXI, VM's or use it to create reporting of status and usage of ESXI and virtual machines and more...

It can be used as a stand alone command line interface but I usually load it into the PowerShell ISE for and troubleshooting scripts.

Download PowerCli 6.5            Download Powershell            Installing Windows PowerShell


    #PowerCLI Version 6.0 Load 

    & 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

    # Or PowerCLI Version 6.5 Load 

    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

 

Load PowerCLI and Login to VMware with Credential Prompt

 

   Function LOAD-PWRCLI {
        
        # \\ Parameters Defined \\
               [CmdletBinding()]
        
                Param(
                    [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$false)]
                    [string]$vCenter_ESXI,
        
                    [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$false)]
                    [string]$UserName,
        
                    [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$false)]
                    [string]$Password
               )
        #\\ Start Processing \\
            Process {
        
                    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
        
                    Connect-VIServer -Server $vCenter_ESXI -Protocol https -User $UserName -Password $Password
                    
                    }
        }       
        
         #\\ Error Trapping \\
            Try{
                LOAD-PWRCLI -ErrorAction Stop
               } 
            Catch
               {
                #\\ Write Out Error Message \\
                Write-host Processing Halted $_.Exception.Message
               }
        

Adds PowerCLI Snapin into Powershell


    Function PWR-CLI {
    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
    write-host ""
    write-host "VMware Core Loaded"
    write-host ""
    }   

Makes a Connection to vCenter/ESXi Host


    Function CON-ServerA {
    Connect-VIServer -Server IP_Address_Here -Protocol https -User Username_Here -Password Password_Here
    write-host ""
    write-host "Conencted to IP_Address_Here ServerA"
    write-host ""
    }       

 

DC Functions so I can disconnect from host


    Function DC-ServerA {
    Disconnect-VIServer -Server IP_Address_Here -confirm:$false
    write-host ""
    write-host "Disconnected from IP_Address_Here ServerA"
    write-host ""
    }