# Invoke-RestMethod OutOfMemory

**URL:** <https://forums.powershell.org/t/invoke-restmethod-outofmemory/23690>\
**Category:** PowerShell Help\
**Created:** [February 29, 2024, 7:06pm UTC](https://forums.powershell.org/t/invoke-restmethod-outofmemory/23690 "2024-02-29T19:06:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imahnobody](https://avatars.discourse-cdn.com/v4/letter/i/a5b964/32.png) [@imahnobody](https://forums.powershell.org/u/imahnobody)\
**Post date:** [February 29, 2024, 7:06pm UTC](https://forums.powershell.org/t/invoke-restmethod-outofmemory/23690/1 "2024-02-29T19:06:24Z")

</div>

I’m trying to retrieve a large dataset from a site using this command

```auto
$alldevices=Invoke-RestMethod -Method "Get" -Uri "https://<website>/Service/Device" -UseBasicParsing -UseDefaultCredentials

```

But am getting this message:

```auto
Invoke-RestMethod : Exception of type 'System.OutOfMemoryException' was thrown.
At line:1 char:13
+ $alldevices=Invoke-RestMethod -Method "Get" -Uri "https://<website> ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], OutOfMemoryException
    + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

```

Then I tried to use this command:

```auto
Invoke-WebRequest -Uri "https://<website>/Service/Device" -UseBasicParsing -UseDefaultCredentials

```

Then I get this message:

```auto
At line:1 char:15
+ ... $alld=Invoke-WebRequest -Uri "https://<website>...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], OutOfMemoryException
    + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

```

Is there a way to get this dataset in chunks, so I don’t run into this memory issue? I’m open to any other way to get this information, too.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [March 2, 2024, 5:32am UTC](https://forums.powershell.org/t/invoke-restmethod-outofmemory/23690/2 "2024-03-02T05:32:21Z")

</div>

Invoke-RestMerhod has a parameter TransferEncoding which you can specify Chunked

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 1, 2024, 5:32am UTC](https://forums.powershell.org/t/invoke-restmethod-outofmemory/23690/3 "2024-04-01T05:32:28Z")

</div>

Closed on April 1, 2024, 5:32am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
