【发布时间】:2022-08-21 00:48:05
【问题描述】:
我在 powershell 中创建了一个 azure 自动化帐户,以获取文件的名称和某些容器中的大小。
我正在通过带有 Webhook 活动的 Azure 数据工厂运行该代码。
该代码对于中小型容器运行得非常好。
问题是,当我尝试为已经有大量文件的某个容器运行代码时,它尝试了 3 次并被挂起,但没有任何反应。我看到了日志,看到了这条消息:
由于沙盒内存不足,Runbook 作业失败。每个 Azure 自动化沙盒都分配有 400 MB 的内存。该作业在暂停之前尝试了 3 次。请参阅https://aka.ms/AAMemoryLimit 解决此问题的一些常用方法
有谁知道如何解决这种情况或者是否可以增加内存?谢谢 !
PS代码:
#define parameters
param (
[Parameter (Mandatory = $false)]
[object] $WebHookData,
[string]$StorageAccountName,
[string]$StorageAccountKey
)
$Parameters = (ConvertFrom-Json -InputObject $WebHookData.RequestBody)
<#If ($Parameters.callBackUri)
{
$callBackUri = $Parameters.callBackUri
}#>
$containerName = $Parameters.containerName
\"->\"+$StorageAccountName
\"->\"+$StorageAccountKey
$connectionName = \"AzureRunAsConnection\"
try
{
# Get the connection \"AzureRunAsConnection \"
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
\"Logging in to Azure...\"
Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = \"Connection $connectionName not found.\"
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
#storage account
$StorageAccountName = $StorageAccountName
#storage key
$StorageAccountKey = $StorageAccountKey
#Container name - change if different
$containerName = $containerName
#get blob context
$Ctx = New-AzStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey
# get a list of all of the blobs in the container
$listOfBlobs = Get-AzStorageBlob -Container $containerName -Context $Ctx
# zero out our total
$length = 0
# this loops through the list of blobs and retrieves the length for each blob
# and adds it to the total
$listOfBlobs | ForEach-Object {$length = $length + $_.Length}
# output the blobs and their sizes and the total
Write-Host \"List of Blobs and their size (length)\"
Write-Host \" \"
$select = $listOfBlobs | Select-Object -Property @{Name=\'ContainerName\';Expression={$containerName}}, Name, @{name=\"Size\";expression={$($_.Length)}}, LastModified
#$listOfBlobs | select Name, Length, @{Name=\'ContainerName\';Expression={$containerName}}
Write-Host \" \"
Write-Host \"Total Length = \" $length
#Define location and Export to CSV file
$SourceLocation = Get-Location
$select | Export-Csv $SourceLocation\'File-size/File-size-\'$containerName\'.csv\' -NoTypeInformation -Force -Encoding UTF8
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Set-AzureStorageBlobContent -Context $Context -Container \"Name\" -File $SourceLocation\"File-size/File-size-$containerName.csv\" -Blob \"File-Size/File-size-$containerName.csv\" -Force
标签: azure powershell azure-devops azure-automation