Advertisement
Sinisterly

Get-PowerCli

Oct 23rd, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Test-PowerCLI
  2. {
  3.     [CmdletBinding()]
  4.     [OutputType([boolean])]
  5.     Param
  6.     (
  7.         # If PowerCLI isn't loaded, loads PowerCLI. Will throw error if it can't load.
  8.         [Parameter(Position=0)]
  9.         [Switch] $LoadIfFalse
  10.     )
  11.  
  12.     Process
  13.     {
  14.         if(get-command connect-viserver -ErrorAction SilentlyContinue)
  15.         {
  16.             return $true
  17.         } elseif ($LoadIfFalse)
  18.         {
  19.             Write-Verbose "PowerCLI check failed, attempting to load PowerCLI"
  20.             add-pssnapin VMWare.vimautomation.core
  21.             if ($?)
  22.             {
  23.                 return $true
  24.             } else {
  25.                 write-error "PowerCLI could not be loaded. Check your PowerCLI installation."
  26.                 return $false
  27.             }
  28.         } else {return $false }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement