function Set-StorageAccounttoPolicy {
$storageaccounts= Get-AzStorageAccount | where {$_.StorageAccountName.StartsWith('p')}
Get-AzRecoveryServicesVault -Name xyztestvault | Set-AzRecoveryServicesVaultContext
$policy=Get-AzRecoveryServicesBackupProtectionPolicy -Name testpolicy
foreach($storage in $storageaccounts) {
$storagename= $storage.StorageAccountName
$resourcegroup= $storage.ResourceGroupName
if($storage.PrimaryEndpoints.File -ne $null)
{
$fileshares= Get-AzRmStorageShare -ResourceGroupName $resourcegroup -StorageAccountName
$storagename
foreach($file in $fileshares)
{
Enable-AzRecoveryServicesBackupProtection -StorageAccountName $storagename -Name
$file.Name -Policy $policy
}
}
}
}
我总是犯错误";启用AzRecoveryServicesBackupProtection:"containerName"不能为null&";,但此存储帐户尚未分配给恢复保管库或策略。我该怎么解决这个问题?
您是否仔细检查了$storagename变量以确保它实际上不是null?此外,请仔细检查当前存储帐户/容器是否与RSV绑定。因为,如果是,它将不允许您运行Enable-AzRecoveryServicesBackupProtection
cmdlet。