title: Invoke-Sqlcmd unable to run
body: <p>I have a PowerShell script that checks the CPU level of the server it is running on, and then if it is above a certain threshold it will run a SQL stored procedure and e-mail.</p>
  
  <p>The script runs correctly on my development server with the latest version of PowerShell. However, I am having issues running the <code>Invoke-Sqlcmd</code> command on the live server I need to get the CPU values from. For sake of example it can be called LIVESERVER. 
  It is running PowerShell 2.0 which I think is the issue:</p>
  
  <blockquote>
    <p>The term 'Invoke-Sqlcmd' 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.</p>
  </blockquote>
  
  <p>I would rather not make any changes to this server as it is business critical (unless this is an easy task to update PowerShell without restarts, etc.).</p>
  
  <p>Is it possible to run my script from my development server and specify the server to get the CPU data from? I'm not sure of how the syntax would work to achieve this.</p>
  
  <p>Here is my script:</p>
  
  <pre class="lang-bsh prettyprint-override"><code># Email 
  $recipients = @("Ricky &lt;ricky@email.com&gt;")
  
  # Loop 20 times
  for ($i= 1; $i -le 20; $i++) {
      # Find CPU average usage percentage for given time period
      $cpuutil = (Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 20 |
                 select -ExpandProperty countersamples |
                 select -ExpandProperty cookedvalue |
                 Measure-Object -Average).Average
  
      # Display average CP output
      $cpuutil
  
      # If CPU average percentage is higher than given value, run stored procedure and
      # e-mail to notify
      if ($cpuutil -ge 60) {
          Invoke-Sqlcmd -Query "SELECT * FROM [Vehicle].[dbo].[tblIndicator]" -ServerInstance "LIVESERVER"
      }
  
      if ($cpuutil -ge 60) {
          Send-MailMessage -From "serverchecks@email.com" -To $recipients -Body "SP Ran" -Subject "Stored Procedure" -Dno onSuccess, onFailure -SmtpServer 111.1.1.111
      } else {
          Start-Sleep -s 10
      }
  }
  </code></pre>