我正在使用AzureRM rest api与虚拟机管理程序进行通信。我需要做的一件事是重置VM上的本地管理员密码,但我无法弄清楚如何重置它。
答案 0 :(得分:1)
我们可以使用Virtual Machine Extensions REST API来做到这一点。它适用于我。以下是我的详细测试信息。
1.我们需要在请求标头中获取authorization
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUz.......
Content-Type:application/json
2.在请求正文中添加以下信息
{
"properties": {
"publisher": "Microsoft.Compute",
"type": "VMAccessAgent",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"settings": {
"UserName": "local admin" //your local admin
},
"protectedSettings": {
"Password": "your reset passord" //match the password policy
}
},
"location": "East Asia"
}
答案 1 :(得分:0)
您还可以使用Azure .NET SDK,它具有create or update call的包装。
我试过并遇到了一个问题,即VM扩展请求已经很好并且安装成功,但密码没有更新。
附上fiddler后,我发现settings
和protectedSettings
的动态对象未被库正确序列化。解决方案是将字典传递给VirtualMachineExtensions()
构造函数。
在:
proxy.VirtualMachineExtensions.BeginCreateOrUpdateWithHttpMessagesAsync(
"<resource group>",
"<vm name>",
"<you name it>",
new Microsoft.Azure.Management.Compute.Models.VirtualMachineExtension(
location: "westus",
publisher: "Microsoft.Compute",
virtualMachineExtensionType: "VMAccessAgent",
typeHandlerVersion: "2.0",
autoUpgradeMinorVersion: true,
settings: new
{
UserName: "<username>"
},
protectedSettings: new
{
Password: "<password>"
}));
后:
proxy.VirtualMachineExtensions.BeginCreateOrUpdateWithHttpMessagesAsync(
"<resource group>",
"<vm name>",
"<you name it>",
new Microsoft.Azure.Management.Compute.Models.VirtualMachineExtension(
location: "westus",
publisher: "Microsoft.Compute",
virtualMachineExtensionType: "VMAccessAgent",
typeHandlerVersion: "2.0",
autoUpgradeMinorVersion: true,
settings: new Dictionary<string, string>()
{
{ "UserName", "<username>" }
},
protectedSettings: new Dictionary<string, string>()
{
{"PassWord", "<password>" }
}));