如何使用.net SDK从恢复服务保险库生成安全PIN ?



目前我正在尝试下面的代码,但得到系统。NullReferenceException: 'Object reference not set to an Object instance .'.

using Microsoft.Azure.Management.RecoveryServices.Backup;
public static ISecurityPINsOperations SecurityPINs { get; }
public static class GenerateSecurityPIN
{
private static readonly ISecurityPINsOperations Operations1;
var pin = await SecurityPINs.GetAsync("rsv-itops-azure-support", "rg-azure-itops-rnd-dev");
}

参考以下链接:https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.recoveryservices.backup.securitypinsoperationsextensions?view=azure-dotnet

您应该使用以下命令安装Microsoft.Azure.Management.RecoveryServices.Backup -Version 4.1.5-preview

Install-Package Microsoft.Azure.Management.RecoveryServices.Backup -Version 4.1.5-preview

然后你的示例代码,应该是这样的,你需要先创建RecoveryServicesBackupClient

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.RecoveryServices.Backup;
using Microsoft.Azure.Management.ResourceManager.Fluent;
namespace ConsoleApp2
{
static class Program
{
static void Main(string[] args)
{
var subscriptionId = "";
var vaultname = "";
var resourcegroup = "";
var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"Auth file path");
var client = new RecoveryServicesBackupClient(credentials) { SubscriptionId = subscriptionId };
var pin = client.SecurityPINs.GetAsync(vaultname,resourcegroup).Result.SecurityPIN;
}
}
}

如果你不想升级包,你也可以使用restapi获取PIN。

相关文章:

使用Powershell或c#获取Azure 'Files and folders'作业状态

最新更新