使用 AzureRM Rest api 在 VM 上重置本地管理员用户
Reset Local Admin User on VM using AzureRM Rest api
我正在使用 AzureRM rest api 与管理程序通信。我需要做的一件事是重置 VM 上的本地管理员密码,但我不知道如何重置它。
我们可以使用 Virtual Machine Extensions REST API 来做到这一点。它对我来说工作正常。以下是我的详细测试信息。
1.We需要获取请求头
中的authorization
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUz.......
Content-Type:application/json
2.Add 请求正文中的以下信息
{
"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"
}
- 使用 Fiddler 发送 http 请求。
4。使用重置密码成功远程 VM。
我们也可以在 Azure 门户中重置我们的本地管理员密码。
您还可以使用 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>" }
}));
我正在使用 AzureRM rest api 与管理程序通信。我需要做的一件事是重置 VM 上的本地管理员密码,但我不知道如何重置它。
我们可以使用 Virtual Machine Extensions REST API 来做到这一点。它对我来说工作正常。以下是我的详细测试信息。
1.We需要获取请求头
中的authorizationAuthorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUz.......
Content-Type:application/json
2.Add 请求正文中的以下信息
{
"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"
}
- 使用 Fiddler 发送 http 请求。
4。使用重置密码成功远程 VM。
我们也可以在 Azure 门户中重置我们的本地管理员密码。
您还可以使用 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>" }
}));