title: Deleting Gmail Emails via Google API using Powershell v2.0
body: <pre><code>$user = "example@gmail.com"
  $pass= "examplepassword" 
  $secpasswd = ConvertTo-SecureString $user -AsPlainText -Force
  $cred = New-Object System.Management.Automation.PSCredential ($pass, $secpasswd)
  
  Invoke-RestMethod  'https://www.googleapis.com/gmail/v1/users/me/messages/0' -Method Delete -Credentials $cred
  </code></pre>
  
  <p>So, my problem here is twofold. </p>
  
  <p>I originally tried using <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/invoke-webrequest" rel="nofollow noreferrer">Invoke-WebRequest</a> to delete gmail emails via the Google API with a http delete request. However, this did not work because <code>Powershell 2.0 does not support Invoke-WebRequest</code>. </p>
  
  <p>Thereafter, I turned to attempting to utilize <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/invoke-restmethod" rel="nofollow noreferrer">Invoke-RestMethod</a> after experimentation with IMAP and POP3, which both required external dependencies (Adding .dlls to the machines I am working with is not optimal). </p>
  
  <p>Therefore, if someone could show me the appropriate way to delete an email via the Google API in Powershell, I would appreciate it. I have provided some sample code as to what I am working with above. Please excuse any mistakes it may contain, as I am relatively new to Powershell, and my experience remains limited in working with RESTful services.</p>