VMware PowerCLI

 

 


Install

 

準備)

Get-ExecutionPolicy -List

LocalMachine

The execution policy affects all users on the current computer. It's stored in the HKEY_LOCAL_MACHINE registry subkey.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

 

Online)

Run as administrator

# Minimum PowerShell version: 3.0

PS> Install-Module -Name VMware.PowerCLI

Offline)

https://developer.vmware.com/web/tool/12.5.0/vmware-powercli

1. Open PowerShell
2. $ENV:PSModulePath.Split(";")
3. Extract the contents of the PowerCLI ZIP file to one of the listed folders.
   (C:\Program Files\WindowsPowerShell\Modules)
4. Get-ChildItem -Path 'folder_path' -Recurse | Unblock-File
5. Get-Module VMware* -ListAvailable

 


Usage

 

載入 module

Import-Module VMware.VimAutomation.Core

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false

Login

# create a variable with preset credentials.

# using the (Get-Credential) option to request the credentials on the console.

$Credenciales = Get-Credential

Connect

# Default: 443/tcp

Connect-VIServer -Server x.x.x.x -Credential $Credenciales

Validate the existing connection

$defaultVIServer

Name                      Port  User
----                      ----  ----
x.x.x.x                   443   MyDomain\Administrator

# Once finished interacting with the vCenter session

Disconnect-VIServer -Server x.x.x.x

# Verify Disconnect

$defaultVIServer

 


應用

 

由 MAC 找出 VM

00:50:56     VMWare

Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -eq "xx:xx:xx:yy:yy:yy" } | Select-Object Parent,Name,MacAddress