注意:要满足的条件
1. powercli 本机,要可以访问esx主机的443,902端口
2. vmtools如果不是最新会有以下提示,.
警告: The version of VMware Tools on VM 'win2019_sec' is out of date and may cause Copy-VMGuestFile to work improperly.
复制文件到vm中
get-vm win2019_sec | Copy-VMGuestFile -LocalToGuest -Source "c:\a.txt" -Destination "c:\" -GuestUser "Administrator" -GuestPassword "myPassw0Rd"
从VM中复制到本地
get-vm win2019_sec | Copy-VMGuestFile -GuestToLocal -Source "c:\a.txt" -Destination "c:\temp\" -GuestUser "Administrator" -GuestPassword "myPassw0Rd"" -Force
-Force 如果目录不存在自动创建
在线安装PowerCLI
https://developer.broadcom.com/powercli
# To install PowerCLI just open a PowerShell console and run the command below:
PS C:\> Install-Module -Name VMware.PowerCLI
离线安装PowerCLI
https://developer.broadcom.com/tools/vmware-powercli/latest
# powershell开启允许运行脚本
set-ExecutionPolicy RemoteSigned
# 下载PowerCLI包后,解压到如下目录中
C:\Program Files\WindowsPowerShell\Modules
# 运行命令
Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules' -Recurse | Unblock-File
# 验证VMware PowerCLI模块是否已成功安装。
Get-Module VMware* -ListAvailable
# 设置powercli的证书机制为ignore。
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
# 带密码连接vCenter
Connect-VIServer -Server 192.168.100.100 -Protocol https -User administrator@vsphere.local -Password myPassw0Rd