LOAD-PWRCLI

<#      .Synopsis   ScriptsbyScott.com      Function to allow connecting to ESXI/vCenter utilizing PowerCLI from VMware    

.DESCRIPTION         Takes input from user for credentials and then loads the Power CLI and connects.    

.EXAMPLE        C:>LOAD-PWRCLI.ps1 

#>  

 

Simple function that uses parameters to prompt for credentials and passes them to connection string to vCenter using PowerCLI cmdlets.

 

 

PowerShell
Edit|Remove
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 
               }