title: Unable to run VCenter powershell script
body: <p>I am trying to connect to VCenter to pull some performance data. When I execute the the script from the powershell window, I get errors:</p>
  
  <p>This is my script:</p>
  
  <pre><code>Connect-VIServer "vcenter.server.com" -User user123 -Password testpassword
  $allvms = @()
  $allhosts = @()
  $hosts = Get-VMHost
  $vms = Get-Vm
  
  foreach($vmHost in $hosts){
    $hoststat = "" | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $hoststat.HostName = $vmHost.name
  
    $statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10 -stat cpu.usage.average
    $statmem = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10 -stat mem.usage.average
  
    $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
    $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
  
    $hoststat.CPUMax = $cpu.Maximum
    $hoststat.CPUAvg = $cpu.Average
    $hoststat.CPUMin = $cpu.Minimum
    $hoststat.MemMax = $mem.Maximum
    $hoststat.MemAvg = $mem.Average
    $hoststat.MemMin = $mem.Minimum
    $allhosts += $hoststat
  }
  $allhosts | Select HostName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\output\Hosts.csv" -noTypeInformation
  
  foreach($vm in $vms){
    $vmstat = "" | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $vmstat.VmName = $vm.name
  
    $statcpu = Get-Stat -Entity ($vm)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10 -stat cpu.usage.average
    $statmem = Get-Stat -Entity ($vm)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10-stat mem.usage.average
  
    $cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
    $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
  
    $vmstat.CPUMax = $cpu.Maximum
    $vmstat.CPUAvg = $cpu.Average
    $vmstat.CPUMin = $cpu.Minimum
    $vmstat.MemMax = $mem.Maximum
    $vmstat.MemAvg = $mem.Average
    $vmstat.MemMin = $mem.Minimum
    $allvms += $vmstat
  }
  $allvms | Select VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\output\VMs.csv" -noTypeInformation
  </code></pre>
  
  <p>These are the error:</p>
  
  <pre><code>The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Chec
  k the spelling of the name, or if a path was included, verify that the path is correct and try again.
  At C:\scripts\vm.ps1:1 char:17
  + Connect-VIServer &lt;&lt;&lt;&lt;  dc1prhsvspvc-01 -User haquem -Password Basketball1
      + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  
  The term 'Get-VMHost' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
  spelling of the name, or if a path was included, verify that the path is correct and try again.
  At C:\scripts\vm.ps1:4 char:20
  + $hosts = Get-VMHost &lt;&lt;&lt;&lt;
      + CategoryInfo          : ObjectNotFound: (Get-VMHost:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  
  The term 'Get-Vm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
  ling of the name, or if a path was included, verify that the path is correct and try again.
  At C:\scripts\vm.ps1:5 char:14
  + $vms = Get-Vm &lt;&lt;&lt;&lt;
      + CategoryInfo          : ObjectNotFound: (Get-Vm:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  
  The term 'Get-Stat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the sp
  elling of the name, or if a path was included, verify that the path is correct and try again.
  At C:\scripts\vm.ps1:11 char:22
  +   $statcpu = Get-Stat &lt;&lt;&lt;&lt;  -Entity ($vmHost)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10 -stat cpu
  .usage.average
      + CategoryInfo          : ObjectNotFound: (Get-Stat:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  
  The term 'Get-Stat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the sp
  elling of the name, or if a path was included, verify that the path is correct and try again.
  At C:\scripts\vm.ps1:12 char:22
  +   $statmem = Get-Stat &lt;&lt;&lt;&lt;  -Entity ($vmHost)-start (get-date).AddDays(-1) -Finish (Get-Date)-MaxSamples 10 -stat mem
  .usage.average
      + CategoryInfo          : ObjectNotFound: (Get-Stat:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  </code></pre>
  
  <p>I am very new to powershell, I really appreciate any help with this?</p>