How to replace Invoke-RestMethod into PowerShell 2.0 -


i have created script in powershell 5.1 retrieves mail messages not older 1 day 'report' subject , save attachments local drive. problem in production environment have powershell 2.0. using invoke-restmethod in code 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 , datetimereceived ge " + $date + " , 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 simple way convert code in order suitable powershell 2.0?

invoke-webrequest 

this command same invoke-restmethod except in how handles data after receives it. going have make small modifications on how parse data.

i'll wager receiving json data run invoke-webrequest command , pipe convertfrom-json , assign results var. let $x.messages | % { $_ }

you need implement converter in 2.0. can copy , paste from: powershell 2.0 convertfrom-json , convertto-json implementation

xml supported in ps 2.0 natively.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -