我已经在PowerShell 5.1中创建了一个脚本,它可以在一天内以“report”作为主题检索不早于的邮件,并将其附件保存到本地驱动器中。问题是在生产环境中我只有Powershell 2.0。我使用的调用,RestMethod在我的代码是这样的:如何将Invoke-RestMethod替换为PowerShell 2.0
$url = "https://outlook.office365.com/api/v1.0/me/messages"
$date = (get-date).AddDays(-1).ToString("yyyy-MM-dd")
$subject = "'report'"
$messageQuery = "" + $url + "?`$select=Id&`$filter=HasAttachments eq true and DateTimeReceived ge " + $date + " and Subject eq " + $subject
$messages = Invoke-RestMethod $messageQuery -Credential $cred
foreach ($message in $messages.value)
{
$query = $url + "/" + $message.Id + "/attachments"
$attachments = Invoke-RestMethod $query -Credential $cred
foreach ($attachment in $attachments.value)
{
$attachment.Name
# SAVE ATTACHMENT CODE HERE
}
}
是否有转换代码,以便为PowerShell 2.0中是合适的一个简单的方法?
[尝试此功能?](https://social.technet.microsoft.com/Forums/scriptcenter/en-US/64c74e89-610e-4229-a56b-12f973232a0a/replace-invokerestmethod-in-powershell-20?forum = ITCG) – ConnorLSW