VMware PowerCLI vCenter批量修改esxi主机root密码

测试环境

1、VMware ESXi-7.0.2-17630552

2、VMware vCenter 7.0.2-17630552

3、Windows Server2019

一、VMware PowerCLI安装

通过在线安装或者离线安装方式操作:

在线安装

可以直接从 PowerShell Gallery安装

Install-Module -Name VMware.PowerCLI

离线安装

1、下载PowerCLI Module.zip文件,此次测试环境版本是VMware-PowerCLI-12.2.0-17538434
2、下载地址:https://developer.vmware.com/web/tool/12.6.0/vmware-powercli
3、检查PowerShell模块路径,执行以下命令(本实验在server2019 powershell中输入)
$env:PSModulePath

在这里插入图片描述

二、 将下载的.zip文件解压缩到PowerShell模块路径

在这里插入图片描述

Powershell执行以下命令以验证PowerCLI模块是否可用

Get-Module -Name VMware.PowerCLI -ListAvailable

在这里插入图片描述

使用Powershell导入模块

对于Powershell,默认禁止运行脚本,需要开放
set-ExecutionPolicy RemoteSigned

在这里插入图片描述

导入模块
Import-Module VMware.PowerCLI

在这里插入图片描述

三、编写批量修改esxi主机root密码脚本

  1. $vCenter = “vcenter-host” 修改为你的vCenter地址
  2. $user = “vcenter-user” 修改为你的vCenter登录用户
  3. $password = “vcenter-passwd” 修改为你的vCenter登录密码
<# vCenter esxi Changing the root Password 
+++++++++++++++++++++++++++++++++++++++++++++++++
+______                      _____  _     _____ +
+| ___ \                    /  __ \| |   |_   _|+
+| |_/ /____      _____ _ __| /  \/| |     | |  +
+|  __/ _ \ \ /\ / / _ \ '__| |    | |     | |  +
+| | | (_) \ V  V /  __/ |  | \__/\| |_____| |_ +
+\_|  \___/ \_/\_/ \___|_|   \____/\_____/\___/ +  
+++++++++++++++++++++++++++++++++++++++++++++++++
                                                                           
#vCenter esxi Changing the root Password 
# .\powercli-vCenter-esxi-change-root-password.ps1
#> 
# vCenter Server configuration
$vCenter = "vcenter-host"
$user = "vcenter-user"
$password = "vcenter-passwd"
Write-Host "connect esxi & vCenter $VMhost" -ForegroundColor Green
# -User 'vcenter-user' 此处需填写vCenter登录用户
Connect-VIServer -Protocol https -User 'vcenter-user' -Password $password -Server $vCenter
Write-Host "Enter new ESXi root password $VMhost" -ForegroundColor Green
$cred = Get-Credential -UserName "root" -message "Enter new ESXi root password"
Write-Host "Select ESXi hosts for changing the root password $VMhost" -ForegroundColor Green
$VMhosts = Get-VMHost | Out-GridView -PassThru -Title "Select ESXi hosts for changing the root password"
Foreach ($VMhost in $VMhosts) {
    
	Write-Host "Look at the host $VMhost" -ForegroundColor Green
    $esxcli = Get-EsxCli -VMhost $VMhost -v2 
	
	Write-Host "Select the host whose password you want to reset $VMhost" -ForegroundColor Green
    $esxcli.system.account.set.Invoke(@{id=$cred.UserName;password=$cred.GetNetworkCredential().Password;passwordconfirmation=$cred.GetNetworkCredential().Password})
}

执行上述脚本 ,在弹窗中输入需要更改的密码

在这里插入图片描述

选中一台或ctrl+A 全选确定进行批量修改,修改后的密码为上一步弹窗中输入的密码

在这里插入图片描述

修改完成

在这里插入图片描述

登录页面测试

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值