I have created a script in PowerShell 5.1 that retrieves mail messages not older that one day with 'report' as a subject and save their attachments into local drive. The problem is that in the production environment I have only Powershell 2.0. I am using Invoke-RestMethod in my code like this:
$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
}
}
Is there a simple way to convert the code in order to be suitable for PowerShell 2.0?