Azure中如何使用Powershell重置VM密码!
第一篇博客,就简单的写一些吧,
因为Azure国际版和国内的Azure(世纪互联)有天壤之别哈,这方面就不做讨论了
就题论题,对于Azure China Cloud上的VM当然了包含 Windows Server & Linux的,国内也只能有这样了!
对于国际版的Azure 无论是 Windows Server 还是Client 同样的 Linux家族的跟丰富啦,详细的就不多说了,说了就泄密了!
问题来了,如果忘记虚拟机的密码如何重置呢
国际版的,就不愧为国际版,UI点下按钮就OK了哈
但对于Azure China Cloud 使用不是那么方便,那么要用Powershell来做了,
请看下面详细:
重置虚拟机登录密码
如果忘记了虚拟机的登录密码,可以通过PowerShell命令修改密码。但重置密码的过程,会导致虚拟机重启。
1.1 重置Windows虚拟机登录密码
$extName = "VMAccessAgent"
$publisher = "Microsoft.Compute"
$ver = "2.0"
$publicConf = '{"UserName":"用户名"}'
$privateConf = '{"Password":"密码"}'
$VM1 = Get-AzureVM -ServiceName "云服务名称" -Name "虚拟机名称"
Set-AzureVMExtension -VM $VM1 -ExtensionName $extName -Publisher $publisher -Version $ver -PublicConfiguration $publicConf -PrivateConfiguration $privateConf | Update-AzureVM
1.2 重置Linux虚拟机登录密码
$vm = Get-AzureVM -ServiceName "云服务名称" -Name "虚拟机名称"
$vm.GetInstance().ProvisionGuestAgent = $true
$pc = '{"username":"用户名","password":"密码"}'
Set-AzureVMExtension -ExtensionName VMAccessForLinux -VM $vm -Publisher "Microsoft.OSTCExtensions" -Version "1.*" -PrivateConfiguration $pc |Update-AzureVM
sleep -Seconds 10
$vm |Restart-AzureVM
完成了,就这么多了吧!