Azure Function running simple Powershell script is running out of Temp folder storage despite the cleanup steps

adm_braskic 0 Reputation points
2024-11-04T09:21:54.9266667+00:00

Hello! I am facing an exception: "Failed to create "C:\local\Temp\tmpEXO..psm1' with allocation size X because the disk was full" with my Azure Function running powershell on consumption plan. I understand that with this plan you only get 0.5GB of temp storage, but my powershell script only connects to Exchange Online and does the cleanup afterwards, so I shouldn't have the exception after couple of requests being sent (it seems temp storage limit is hit after about 20 subsequent HTTP requests in a row):

using namespace System.Net

param($Request, $TriggerMetadata)

Connect-ExchangeOnline -ManagedIdentity -Organization ORGANIZATION.onmicrosoft.com

Disconnect-ExchangeOnline -Confirm:$false

# Associate values to output bindings by calling 'Push-OutputBinding'.

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

StatusCode = [HttpStatusCode]::OK

Headers = @{

"Content-type" = "application/json"

}

})

Is there a way to erase the temp folder content after every HTTP invocation of this function?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. David Broggy 6,371 Reputation points MVP Volunteer Moderator
    2024-11-04T17:29:49.52+00:00

    Hi adm,

    Have you tried a command like this?

    ###Remove specific temp folders created by Connect-ExchangeOnline

    Get-ChildItem -Path $TempPath -Recurse -Force -ErrorAction SilentlyContinue | Where-Object { $.PSIsContainer -and $.Name -like "tmpEXO*" } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.