Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure 用于从blob容器的子文件夹中删除文件的Powershell脚本_Azure_Powershell_Blob_Azure Storage - Fatal编程技术网

Azure 用于从blob容器的子文件夹中删除文件的Powershell脚本

Azure 用于从blob容器的子文件夹中删除文件的Powershell脚本,azure,powershell,blob,azure-storage,Azure,Powershell,Blob,Azure Storage,我正在尝试从特定文件夹中删除文件,如从blob容器中的full或diff,但无法执行此操作。 容器名称,然后有两个文件夹full和diff,我只想从full中删除文件。 请帮忙 $context = New-AzureStorageContext -StorageAccountName "storage_name" -StorageAccountKey "key" $blobs= Get-AzureStorageBlob -Container "container_name" -blob *

我正在尝试从特定文件夹中删除文件,如从blob容器中的full或diff,但无法执行此操作。 容器名称,然后有两个文件夹full和diff,我只想从full中删除文件。 请帮忙

$context = New-AzureStorageContext -StorageAccountName "storage_name" -StorageAccountKey "key"


$blobs= Get-AzureStorageBlob -Container "container_name" -blob *DIFF*.bak -Context $context
foreach ($blob in $blobs)
{
$modifieddate = $blob.LastModified
Write-Host $modifieddate

if ($modifieddate -ne $null) 
    {
        $howold = ([DateTime]::Now - [DateTime]$modifieddate.LocalDateTime) 

        if ($howold.TotalDays -ge 5)
            {
                Remove-AzureStorageBlob -Blob $blob.Name -Container "container_name" -Context $context
                Write-Host $blob.Name
            }
    }

 }

如果要使用Azure PowerShell从一个容器中的一个子文件夹中删除Blob,可以使用以下脚本:

$StorageAccountKey=" "
$StorageAccountName=" "
$ContainerName=" "
$Token = $null
$Total = 0
$MaxCount=5000
$context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
do
 { 
     $Blobs =  Get-AzStorageBlob -Container $ContainerName -MaxCount $MaxCount  -ContinuationToken $Token -Context $context -Prefix "your fodler name"
     if($Blobs.Length -le 0) { Break;}
     $Token = $Blobs[$blobs.Count -1].ContinuationToken;

     foreach($blob in $blobs){
        Remove-AzStorageBlob -Blob $blob.Name -Container $ContainerName -Context $context

     }


 }
 While ($Token -ne $null)  
更新

我使用最新版本的Azure Az模块进行测试。

它的可能副本不起作用。错误为无法识别前缀命令根据我的测试,命令Get-AzStorageBlob具有参数前缀。有关更多详细信息,请参阅将AzureStorage替换为AzureStorage后,它工作正常。