【发布时间】:2017-05-05 08:27:58
【问题描述】:
$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
所以,我的问题是双重的。
我最初尝试使用 Invoke-WebRequest 通过带有 http 删除请求的 Google API 删除 gmail 电子邮件。但是,这不起作用,因为Powershell 2.0 does not support Invoke-WebRequest。
此后,我在尝试使用 IMAP 和 POP3 后尝试使用 Invoke-RestMethod,这两者都需要外部依赖项(将 .dlls 添加到我正在使用的机器不是最佳选择)。
因此,如果有人可以向我展示通过 Powershell 中的 Google API 删除电子邮件的适当方法,我将不胜感激。我已经提供了一些示例代码来说明我在上面使用的内容。请原谅它可能包含的任何错误,因为我对 Powershell 比较陌生,而且我在使用 RESTful 服务方面的经验仍然有限。
【问题讨论】:
-
你看过technet吗?
-
我看过 Technet,是的。它没有提供有关如何与 Google 的 OAuth2.0 及其 API 交互的示例,所以这就是我遇到问题的地方。
-
Invoke-restmethod 也是 PoSH 3 及更高版本的 cmdlet。
-
Fun.... 好吧,至少我得到了另一个节点来运行它,它应该启用 Powershell v5。
标签: powershell google-api gmail google-oauth powershell-2.0