安装PowerCLI并使用脚本导出虚拟机信息
安装PowerCLI
从官网下载模块包
https://developer.vmware.com/web/tool/vmware-powercli
解压到C:\Program Files\WindowsPowerShell\Modules
PowerShell执行Install-Module -Name VMware.PowerCLI
进行安装
测试连接vCenterConnect-VIServer <vcenteraddress> -User <username> -Password <password>
如果提示SSL错误,执行Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
忽略证书信息
使用脚本导出虚拟机信息
先解除脚本的运行限制set-ExecutionPolicy RemoteSigned
脚本代码
$date = get-date -UFormat %Y%m%d_%H%M%S
$vcenterlist = Read-Host("address" )
$username = Read-Host("username" )
$passwd = Read-Host("password" )
$path = Read-Host("export path")
foreach ($vcenter in $vcenterlist){
Connect-VIServer $vcenter -User $username -Password $passwd | Out-Null
get-vm | Select-Object Name, PowerState,VMhost, MemoryGB, NumCpu, @{ n="DiskUsedGB"; e={[math]::round( $_.UsedSpaceGB )}},
@{N="CapacityGB";E={$_.HardDisks.CapacityGB}},
@{N="IPAddress";E={@($_.guest.IPAddress[0])}},
@{N="State";E={$_.Guest.State}},
@{N="OS";E={$_.Guest.OSFullName}},
@{N="Version";E={$_.Version}},
@{N="Notes";E={$_.Notes}} | Export-Csv -NoTypeInformation -Encoding OEM $path\"$vcenter"_"$date".csv
}
Write-Host 'complete'
Read-Host
运行脚本,根据提示输入地址、用户名、密码、导出路径(如:D:\tmp)