"Vsphere Powercli 5.8 Cheat Sheet - Vmware"

ADVERTISEMENT
ADVERTISEMENT

Download "Vsphere Powercli 5.8 Cheat Sheet - Vmware"

450 times
Rate (4.6 / 5) 31 votes
VMware vSphere PowerCLI 5.8 Release 1 Reference Poster
PowerCLI Settings
Datacenter Operations
Cluster Operations
Guest OS
Host Operations
Network Operations
vCloud Tenant Operations
Dismount-Tools
Get-iScsiHbaTarget
Get-ScsiLunPath
Get-VDSwitch
Get-VirtualSwitch
Get-VMHostHba
Get-ErrorReport
Get-Datacenter
Get-Cluster
Get-CDDrive
Get-Template
New-CIAccessControlRule
Mount-Tools
New-iScsiHbaTarget
Set-ScsiLunPath
Get-VDSwitchPrivateVlan
New-VirtualSwitch
Set-VMHostHba
Get-DatastoreCluster
Get-PowerCLICommunity
Move-Datacenter
New-CDDrive
Move-Template
Remove-CIAccessControlRule
Update-Tools
Remove-iScsiHbaTarget
Get-SecurityPolicy
New-VDSwitch
Remove-VirtualSwitch
Get-VMHostNetwork
Get-PowerCLIConfiguration
New-Datacenter
Move-Cluster
Update Manager
Update Manager
Remove-CDDrive
Set-CIAccessControlRule
New-Template
Set-iScsiHbaTarget
Set-SecurityPolicy
New-VDSwitchPrivateVlan
Set-VirtualSwitch
Set-VMHostNetwork
Wait-Tools
Set-PowerCLIConfiguration
New-Cluster
Remove-Datacenter
Set-CDDrive
Remove-Template
Set-CINetworkAdapter
Get-VMGuest
Get-NicTeamingPolicy
Get-VDBlockedPolicy
Remove-VDSwitch
Add-VirtualSwitchPhysicalNetworkAdapter
Get-VMHostNetworkAdapter
vSphere
vCloud
Licensing
Get-PowerCLIDocumentation
Set-Datacenter
Remove-Cluster
Get-FloppyDrive
Set-CIVAppNetwork
Set-Template
Image
Set-NicTeamingPolicy
Get-VDPort
Remove-VDSwitchPhysicalNetworkAdapter
Remove-VirtualSwitchPhysicalNetworkAdapter
New-VMHostNetworkAdapter
Restart-VMGuest
Get-PowerCLIVersion
Set-Cluster
vSphere
vCloud
Licensing
New-FloppyDrive
Get-UsbDevice
Set-CIVAppStartRule
Get-OSCustomizationNicMapping
Export-VDPortGroup
Remove-VDSwitchPrivateVlan
Get-VMGuestNetworkInterface
Remove-
Shutdown-VMGuest
Builder
Remove-FloppyDrive
Remove-UsbDevice
Set-CIVAppTemplate
New-OSCustomizationNicMapping
Get-VDPortgroup
Remove-VDSwitchVMHost
Set-VMGuestNetworkInterface
VMHostNetworkAdapter
SRM
Suspend-VMGuest
Set-FloppyDrive
New-CIVApp
Get-VM
Remove-OSCustomizationNicMapping
New-VDPortgroup
Get-VDTrafficShapingPolicy
Get-VMGuestRoute
Set-VMHostNetworkAdapter
Copy-VMGuestFile
PowerCLI
Copy-HardDisk
Move-VM
Set-OSCustomizationNicMapping
Remove-VDPortGroup
Get-VDUplinkLacpPolicy
New-VMGuestRoute
Add-VmHostNtpServer
Remove-CIVApp
VMware vSphere Server
Get-VMGuestNetworkInterface
Get-HardDisk
Get-ScsiController
Get-VDPortgroupOverridePolicy
Get-VDUplinkTeamingPolicy
Remove-VMGuestRoute
Get-VMHostNtpServer
Restart-CIVApp
New-VM
Get-AdvancedSetting
Get-Datastore
Get-Task
Set-VMGuestNetworkInterface
New-ScsiController
Export-VDSwitch
Get-VirtualPortGroup
Get-VMHostFirewallDefaultPolicy
Remove-VMHostNtpServer
New-HardDisk
Restart-VM
Set-CIVApp
New-AdvancedSetting
Get-VMGuestRoute
Set-Datastore
Stop-Task
Set-ScsiController
Add-VDSwitchPhysicalNetworkAdapter
New-VirtualPortGroup
Set-VMHostFirewallDefaultPolicy
Test-VMHostSnmp
View
View
Remove-HardDisk
Remove-VM
Start-CIVApp
New-VMGuestRoute
Remove-AdvancedSetting
Copy-DatastoreItem
Wait-Task
Get-ScsiLun
Add-VDSwitchVMHost
Remove-VirtualPortGroup
Get-VMHostFirewallException
Get-VMHostSnmp
Auto
Image
Set-HardDisk
Set-VM
Stop-CIVApp
Set-AdvancedSetting
Get-VIAccount
Remove-VMGuestRoute
Set-ScsiLun
Get-VDSecurityPolicy
Set-VirtualPortGroup
Set-VMHostFirewallException
Set-VMHostSnmp
Apply-DrsRecommendation
Storage
New-NetworkAdapter
Start-VM
Suspend-CIVApp
Auto
Invoke-VMScript
Get-AlarmAction
Get-DrsRecommendation
Get-View
Deploy
Builder
PowerCLI
Remove-NetworkAdapter
Restart-CIVAppGuest
VSAN
STORAGE
Stop-VM
New-AlarmAction
Get-DrsRule
Get-VIObjectByVIView
Deploy
Set-NetworkAdapter
Suspend-VM
PowerShell for View Operations
Storage Policy Based Management
Stop-CIVAppGuest
Remove-AlarmAction
New-DrsRule
Get-VIPermission
Host Profiles
Add-PassthroughDevice
Open-VMConsoleWindow
New-CIVAppNetwork
Get-CompatibleStorage
Get-AlarmActionTrigger
Remove-DrsRule
New-VIPermission
Add-AutomaticPool
Get-GlobalSetting
Update-TerminalServerPool
Add-ManualUnmanagedPool
Get-PassthroughDevice
Get-VMQuestion
Remove-CIVAppNetwork
Apply-VMHostProfile
New-AlarmActionTrigger
Remove-VIPermission
Get-SpbmCapabilityMetadata
Set-DrsRule
Update-AutomaticPool
Update-GlobalSetting
Update-ManualUnmanagedPool
Get-RemoteSession
Remove-PassthroughDevice
Set-VMQuestion
Import-CIVAppTemplate
Export-VMHostProfile
Get-SpbmComplianceStatus
Remove-AlarmActionTrigger
Get-EsxCli
Set-VIPermission
Add-AutomaticLinkedClonePool
Get-License
Get-Monitor
Send-SessionDisconnect
Get-Snapshot
New-CIVAppTemplate
vCloud
Get-VMResourceConfiguration
vCloud
Get-VMHostProfile
Get-AlarmDefinition
Get-EsxTop
Get-VIPrivilege
Update-AutomaticLinkedClonePool
Set-License
Get-SpbmEntityConfiguration
Get-Pool
Send-SessionLogoff
New-Snapshot
Set-VMResourceConfiguration
Remove-CIVAppTemplate
Import-VMHostProfile
Set-SpbmEntityConfiguration
Set-AlarmDefinition
Move-Folder
New-VIProperty
Tenant
Tenant
Get-ComposerDomain
Send-LinkedCloneRebalance
Remove-Pool
Get-User
Remove-Snapshot
Get-VMStartPolicy
New-CIVM
PowerShell
New-VMHostProfile
New-SpbmRule
Get-Annotation
New-Folder
Remove-VIProperty
PowerShell
Get-ConnectionBroker
Send-LinkedCloneRecompose
Remove-UserOwnership
Add-PoolEntitlement
Set-Snapshot
Set-VMStartPolicy
Restart-CIVM
Remove-VMHostProfile
Set-Annotation
Get-VIRole
New-SpbmRuleSet
Get-Folder
Update-ConnectionBroker
Send-LinkedCloneRefresh
Get-PoolEntitlement
Update-UserOwnership
Start-CIVM
Set-VMHostProfile
New-SpbmStoragePolicy
Get-CustomAttribute
Remove-Folder
New-VIRole
Get-DesktopPhysicalMachine
Get-LocalSession
Remove-PoolEntitlement
Add-ViewVC
Stop-CIVM
Test-VMHostProfileCompliance
New-CustomAttribute
Set-Folder
Remove-VIRole
Get-DesktopVM
Send-LocalSessionRollback
Set-SpbmStoragePolicy
Get-ProfileDisk
Get-ViewVC
Suspend-CIVM
Get-SpbmStoragePolicy
Remove-CustomAttribute
Get-Inventory
Set-VIRole
Get-EventReport
Add-ManualPool
Get-TerminalServer
Remove-ViewVC
Restart-CIVMGuest
Remove-SpbmStoragePolicy
Set-CustomAttribute
Move-Inventory
Connect-VIServer
Get-EventReportList
Update-ManualPool
Auto Deploy Operations
Licensing Operations
vCenter Update Manager
Add-TerminalServerPool
Update-ViewVC
Stop-CIVMGuest
New-Datastore
Disconnect-VIServer
Virtual Machine Host Operations
Get-SpbmView
Remove-Inventory
Send-VMReset
Search-Cloud
Switch-ActiveDeployRuleSet
Export-StorageProfile
Remove-Datastore
Get-NetworkAdapter
Set-Org
Get-HAPrimaryVMHost
Get-VMHostAccount
Get-LicenseDataManager
Get-VMHostDisk
Get-VMHostRoute
Repair-DeployImageCache
Get-VMHostStartPolicy
Import-StorageProfile
Add-VMHost
New-VMHostAccount
Attach-Baseline
Set-PowerCLIConfiguration
Format-VMHostDiskPartition
New-VMHostRoute
Add-DeployRule
Set-VMHostStartPolicy
vCloud Operations
Get-PowerCLIVersion
Get-VMHost
Set-VMHostAccount
Detach-Baseline
Get-VMHostDiskPartition
Remove-VMHostRoute
Get-VMHostSysLogServer
Copy-DeployRule
Logs/Reporting/Configuration
vApps
Move-VMHost
Remove-VMHostAccount
Get-Baseline
Get-Task
Get-VMHostFirmware
Set-VMHostRoute
Get-DeployRule
Image Builder Operations
Set-VMHostSysLogServer
Connect-CIServer
Get-CIUser
Set-CIVAppNetwork
Start-CIVM
Get-Org
Resource Pool Operations
Get-VMHostAdvancedConfiguration
Remove-Baseline
Tags
Stop-Task
Remove-VMHost
Set-VMHostFirmware
Get-VMHostService
Get-ErrorReport
New-DeployRule
Disconnect-CIServer
Start-CIVApp
Get-CIVAppNetwork
Stop-CIVM
Set-StatInterval
Compare-EsxImageProfile
Remove-Org
Export-vApp
Wait-Task
Restart-VMHost
Set-VMHostAdvancedConfiguration
Get-Compliance
Get-ResourcePool
Get-VMHostModule
Restart-VMHostService
Remove-DeployRule
Get-Catalog
Import-CIVApp
Remove-CIVAppNetwork
Get-Log
Get-StatType
Export-EsxImageProfile
Restart-CIVM
Set-Org
Get-Tag
Get-vApp
Set-VMHost
Get-VMHostAuthentication
Download-Patch
Get-VICredentialStoreItem
Set-VMHostModule
Set-VMHostService
Set-DeployRule
Get-CIAccessControlRule
New-CIVApp
Move-ResourcePool
Get-LogType
New-CIVAppNetwork
New-CIVM
New-Org
Get-VICredentialStoreItem
Get-EsxImageProfile
New-Tag
Import-vApp
New-VICredentialStoreItem
Start-VMHost
Set-VMHostAuthentication
Get-Patch
Set-CIAccessControlRule
Restart-CIVApp
New-ResourcePool
Get-OSCustomizationSpec
Get-VMHostPatch
Start-VMHostService
Get-DeployRuleSet
Set-CIVAppStartRule
Get-CIVM
New-OrgVdc
New-VICredentialStoreItem
New-EsxImageProfile
Remove-Tag
Move-Vapp
Stop-VMHost
Get-VMHostAvailableTimeZone
Stage-Patch
New-CIAccessControlRule
Remove-CIVApp
Remove-VICredentialStoreItem
Install-VMHostPatch
Stop-VMHostService
Set-DeployRuleSet
Get-CIVAppStartRule
Suspend-CIVM
Remove-OrgVdc
Remove-ResourcePool
New-OSCustomizationSpec
Set-Tag
Remove-VICredentialStoreItem
Set-EsxImageProfile
New-vApp
Get-VMHostDiagnosticPartition
Get-PatchBaseline
Remove-CIAccessControlRule
Set-CIVApp
Suspend-VMHost
Get-VMHostProfileRequiredInput
Import-CIVAppTemplate
Stop-CIVMGuest
Set-OrgVdc
Remove-OSCustomizationSpec
Get-VMHostStorage
Repair-DeployRuleSetCompliance
Set-ResourcePool
Get-TagAssignment
Get-VMHostSysLogServer
Get-EsxSoftwareChannel
Remove-vApp
Add-CIDatastore
Stop-CIVApp
Set-VMHostDiagnosticPartition
New-PatchBaseline
Remove-CIVAppTemplate
Restart-CIVMGuest
Get-OrgVdc
Set-VMHostStorage
Test-DeployRuleSetCompliance
New-TagAssignment
Set-OSCustomizationSpec
Set-VMHostSysLogServer
Add-EsxSoftwareDepot
Get-CIDatastore
Suspend-CIVApp
Set-vApp
Set-PatchBaseline
Set-CIVAppTemplate
Search-Cloud
Get-ProviderVdc
Apply-ESXImageProfile
Remove-TagAssignment
Get-Stat
Get-VMResourceConguration
Remove-EsxSoftwareDepot
Set-CINetworkAdapter
Get-CIVApp
OVF Configuration
Site Recovery Manager
Start-vApp
Get-CIVAppTemplate
Get-ExternalNetwork
Get-OrgNetwork
Remediate-Inventory
Get-TagCategory
Get-VMHostAttributes
Get-StatInterval
Get-VIEvent
Add-EsxSoftwarePackage
Get-CINetworkAdapter
Stop-CIVAppGuest
New-CIVAppTemplate
Get-Media
Remove-OrgNetwork
Stop-vApp
Scan-Inventory
New-TagCategory
Get-VMHostImageProfile
Connect-SrmServer
New-StatInterval
Get-CIRole
Get-VIProperty
Get-EsxSoftwarePackage
Restart-CIVAppGuest
Get-CIView
Get-NetworkPool
Set-OrgNetwork
Get-OVFConfiguration
Remove-TagCategory
Disconnect-SrmServer
Remove-StatInterval
Get-VMHostMatchingRules
New-VIProperty
Remove-EsxSoftwarePackage
New-OrgNetwork
Set-TagCategory
VMware vSphere PowerCLI Quick Reference Examples
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Getting Started
Virtual Switch Operations
Task Information
vApp Operations
ESXTOP through PowerCLI
Quick Helpful Commands
Leverage Jobs for Multi-threaded Operations
Image Builder
VMware vSphere PowerCLI frequently asked questions (FAQs) link:
To list all virtual switches attached to a VM and some of their properties, use:
The following is a list of vApp cmdlets; use the Get-Help function for example uses:
Get-EsxTop –Counter
Top 5 VM memory allocation:
Jobs allow users to run scripts in parallel.
Connect to a depot:
To list all tasks for a VMware vSphere server and some of their properties:
http://communities.vmware.com/docs/DOC-13700
New-vApp -Name
MyvApp
-CpuLimitMhz
4000
-CpuReservationMhz
1000
-Location
# View the fields available for vCPU counter:
Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
Get-VirtualSwitch -VM (Get-VM -Name
"Lync-Edge-03")
Get-Task
Get-VM
|
Sort-Object -Property
MemoryGB
-Descending
|
Select -
Create a script that will be run in a job:
To find out what cmdlets are available:
Get-VICommand
To create a new virtual switch:
To stop a task (example: stops the task of removing the VM):
(Get-VMHost
MyHost)
(Get-EsxTop –Counter
–CounterName
VCPU).Fields
First
5
$jobscript
=
{
Add a package by name to an image profile:
To show documentation for all available cmdlets:
Get-PowerCLIDocumentation
New-VirtualSwitch -VMHost (Get-VMHost -Name
192.168.0.10) -Name
Switch02
Get-EsxTop –TopologyInfo
# Add PowerCLI Snapin
Add-EsxSoftwarePackage -ImageProfile "My custom profile" -SoftwarePackage net-bnx2
Stop-Task -Task (Remove-VM -VM
"Lync-Edge-03"
-Confirm
-RunAsync)
Other vApp cmdlets:
Remove-vApp
To remove a virtual switch:
# View the entries of a specific topology:
Clone an image profile, then add a package by name:
For help with a cmdlet:
Get-Help
cmdlet-name
–Full
To wait until a task is completed before continuing:
Add-PSSnapin
VMware.VimAutomation.core
Export-vApp
Total memory available on all ESXi:
Set-vApp
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
VS23
(Get-EsxTop –TopologyInfo
–Topology
SchedGroup).Entries | FT
# Connect to vCenter
New-EsxImageProfile -CloneProfile "ESX-5.0-234567-standard" -Name "My custom profile" | Add-EsxSoftwarePackage net-bnx2
Wait-Task -Task (Remove-VM -VM
"Lync-Edge-03"
-Confirm
-RunAsync)
Get-VMHost
|
Measure-Object -Property
MemoryTotalGB
-Sum
|
Get-vApp
Start-vApp
Remove-VirtualSwitch -VirtualSwitch
$vs
# Retrieve the counter values for “VCPU” and “SchedGroup" counters:
Connect-VIserver
vcsa.lab.local
-User
root
-Password
"VMware1!"
Export an ISO image
Import-vApp
Stop-vApp
Select -ExpandProperty
Sum
How to Connect to vCenter Server or ESXi
To change the configuration of a virtual switch:
Get-EsxTop –CounterName VCPU
| FT * -AutoSize
# Create Snapshots of all LabTest VM's
Export-EsxImageProfile -ImageProfile "Evan's Profile" -ExportToIso -FilePath c:\isos\evans-iso.iso
$vs =
New-VirtualSwitch -Host
192.168.0.10
-Name
VirtSwitch
Get-EsxTop –CounterName SchedGroup
| FT * -AutoSize
Get-VM
"LABTEST*"
|
New-Snapshot -Name
InitialSnapshot}
Clone an image profile, add a software package, then export to offline bundle.
Tag Operations
Report on NumCPU and number of VM:
To connect to a VMware vSphere server. Start a new session or reestablish a
New-EsxImageProfile -CloneProfile "ESXi-5.0.0-234567-standard" -Name "Evan's Profile"
Set-VirtualSwitch -VirtualSwitch
$vs
-MTU
500
previous session with a VMware vSphere server.
Get-VM
|
Group-Object -Property
NumCpu
|
To start the Job:
Add-EsxSoftwarePackage -ImageProfile "Evan's Profile" -SoftwarePackage cisco-vem-v140
Create a tag category:
OVF Configuration
Export-EsxImageProfile -ImageProfile "Evan's Profile" -ExportToBundle -FilePath c:\isos\base-plus-vem.zip
$srv =
Connect-VIServer –Server
192.168.0.10
-User
Admin
-Password
Pass01
Select
@{N="NumCpu";E={$_.Name}},@{N="Number of
Start-Job -Name
Snapshots
-ScriptBlock
$jobscript
Port Group Operations
New-TagCategory -Name
"Owner"
-Cardinality
Single
-EntityType
To disconnect from the connected vSphere server:
VM";E={$_.Count}}
Display all image profiles from depots and all image profiles the user created during this PowerCLI session:
Resource Pool Operations
VirtualMachine
Using OVFConfiguration to deploy vApps:
When Jobs are running you can use
Get-Job
to see the status:
Get-EsxImageProfile
Disconnect-VIServer -Server
$srv -Confirm:$false
To list all the port groups and some of their properties:
$ovfconfig
=
get-OvfConfiguration
“myOvfTemplate.ovf”
Remove-TagCategory
"Owner"
List all the VIBs, sorted by date:
Get-Job
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
Switch02
Most API methods require parameters.
To list all resource pools on the connected VMware vSphere server and some of
Create a tag:
$ovfconfig.ToHashtable()
Get-Job -Name
Snapshots
Get-EsxSoftwarePackage | Sort-Object ReleaseDate | Format-Table -Property Name,Version,Vendor
Get-VirtualPortGroup -VirtualSwitch
$vs
You create those with New-Object:
their properties:
Get-ResourcePool
$myTag =
New-Tag -Name
"jSmith"
-Category
"Owner"
Get-Job -Id
1
List all the VIBs from VMware and Cisco released after Jan 1, 2010:
How to Connect to SRM
To add a new port group to a virtual switch:
Use a hashtable:
$vm
=
Get-VM -Name
MyVM
Assign a tag:
Get-EsxSoftwarePackage -Vendor "VMware","Cisco" -ReleasedAfter 1/1/2010
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
Switch02
To create a new resource pool:
$ovfconfig
=
@{
$spec
=
New-Object
VMware.Vim.VirtualMachineConfigSpec
Get-VM -Name
"Lync-Edge-*"
|
New-TagAssignment -Tag
$myTag
You can stop a job manually:
List all the VIBs from vendors other than VMware
Connect to vCenter Server first
$vpg =
New-VirtualPortGroup -VirtualSwitch
$vs
-Name
VPG1
$clusterRootRP
=
Get-ResourcePool -Location
"vami.DNS.VMware_vCenter_Log_Insight"
=
"10.144.99.5";
$spec.latencySensitivity
=
New-Object
Get-VM -Tag
"jSmith"
Get-Job -Name
Snapshots
|
Stop-Job
Get-EsxSoftwarePackage | ? {$_.Vendor -ne "VMware"}
Other cmdlets include:
Connect-SrmServer -SrmServerAddress
10.144.99.6
-User
(Get-Cluster
ResearchAndDevelopmentCluster
) -Name Resources
"vami.gateway.VMware_vCenter_Log_Insight"
=
"10.144.99.1";
VMware.Vim.LatencySensitivity
Clone an image profile, give it a new name, and change the acceptance level.
"administrator"
-Password
"myPassword"
"vami.ip0.VMware_vCenter_Log_Insight"
=
"10.144.99.30";
Remove-VirtualPortGroup
New-ResourcePool -Location
$clusterRootRP
-Name
DevelopmentResources
New-EsxImageProfile -CloneProfile "ESX-5.0-234567-standard" -Name "My custom profile" -AcceptanceLevel CommunitySupported
$spec.LatencySensitivity.Level
=
To see the results of the script you can receive the job
Set-VirtualPortGroup
-CpuExpandableReservation
$true
-CpuReservationMhz
"vami.netmask0.VMware_vCenter_Log_Insight"
=
"255.255.255.0";
Disconnect-SrmServer -Server
10.144.99.6
[VMware.Vim.LatencySensitivitySensitivityLevel]::high
use the
-Keep
parameter to allow this information to stay:
Connect to a depot, then disconnect from it by URL.
500
-CpuSharesLevel
high
-MemExpandableReservation
$true
"vm.rootpw"
=
"VMware1!";}
Get-Job -Name
Snapshots
|
Receive-Job -Keep
Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
$vm.ExtensionData.reReconfigVM($spec)
-MemReservationMB
500
-MemSharesLevel
high
Remove package foo from my custom profile:
Managing Events Alarms
When finished with a job you may remove it:
API Operations
Or populate an object:
Get-Job -Name
Snapshots
|
Remove-Job
Remove-EsxSoftwarePackage -ImageProfile "My custom profile" -SoftwarePackage foo
Other resource pool cmdlets:
$ovfconfig.NetworkMapping.Network.Value =
“Network
1”
Modify the VIB list of an existing image profile
Get-AlarmDefinition
# Returns all the defined alarms on the servers
Move-ResourcePool
$ovfconfig.vami.VM_1.ip0.Value = “10.144.99.30”
How to Store vCenter Credentials
Returns a VMware vSphere.Net view object by specified search
you’re connected to.
Set-EsxImageProfile -ImageProfile "Profile of a Fool" -SoftwarePackage esx-base,scsi-ips,esx-tboot
Remove-ResourcePool
$ovfPath
= “c:\temp\myOvfTemplate.ovf”
criteria.
Get-AlarmDefinition -Name "virtual machine*"
-Enabled $false
Set-ResourcePool
Snapshot Operations
PowerCLI Info
$vm =
Get-View -ViewType
VirtualMachine
-Filter
@{"Name" = "MS
Method to not have to input credentials every time you connect to
# Returns all the disabled alarm definitions with names starting with
Import-Vapp
$ovfPath
-OvfConfiguration
$ovfConfig
-VMHost
$vmHost
-Name
“VM_OVF”
vCenter:
Win XP
SP2"}
“virtual machine.”
Datastore Operations
Folder Operations
To list all the snapshots for all virtual machines:
PowerCLI Sites
PowerCLI Books
$hostView =
Get-View -ID
$vm.Runtime.Host
Get-VMHost hostname
|
Get-AlarmDefinition
# Returns all alarms that
New-VICredentialStoreItem -Host
vCSA.lab.local
-User
Root
-
Get-VM
|
Get-Snapshot
Copy Files To/From VM
What is PowerCLI?
$hostView.Summary.Runtime
apply to the host “hostname”. Includes alarms defined on this host and
For a list of datastores and other
The following is a list of all folder-
Password
"VMware1!"
To snapshot a VM:
Official PowerCLI Blog -
http://blogs.vmware.com/PowerCLI/
Learning PowerCLI
Another example:
alarms inherited from the parent entity, or from any ancestors in the
properties:
related cmdlets:
New-Snapshot
-VM "XP SP2"
-Name
BeforePatch1
To remove credentials:
Invoke Commands In Virtual Machines
Documentation -
http://vmware.com/support/developer/PowerCLI /index.html
inventory hierarchy.
Get-Datastore
Get-Folder
VMware vSphere PowerCLI is a powerful,
(Get-View (Get-VMHost
'ESX1'
|
get-view).ConfigManager
Remove-VICredentialStoreItem -Host
vCSA.lab.local
-Confirm
Files can be copied between user’s local machine and a VM
To remove a snapshot:
VMware PowerCLI Community -
http://vmware.com/go/powercli
easy-to-use scripting interface to manage
Managing VMware Infrastructure with Windows
.VmotionSystem).SelectVnc('vmk0')
Modify an alarm definition:
Get-AlarmDefinition
"Host memory status" |
Move-Folder
Remove-Snapshot -Snapshot
$snapshot1
Twitter -
https://twitter.com/PowerCLI
Copy from a VM to the Local Machine:
Invoke-VMScript
allows BIN, BASH, and Powershell Commands to be invoked remotely
the vSphere platform. Administrators can
Set-AlarmDefinition -Name "Host memory"
-Enabled $false
Other datastore cmdlets include:
New-Folder
PowerShell TFM
API Reference:
RemoveChildren
LinkedIn -
http://www.linkedin.com/groups/PowerCLI-Users-162324
Copy-VMGuestFile -VM
LABTEST1
-GuestUser
Administrator
-GuestPassword
Invoke-VMScript -VM
LABTEST1
-ScriptText
"dir"
-GU
Administrator
-GP
"VMware1!"
New-Datastore
Remove-Folder
Leverage more than 360 cmdlets
https://www.vmware.com/support/developer/vc-sdk/
# This will rename the alarm to “Host memory” and disable it.
Facebook -
https://www.facebook.com/vmwarepowercli
Other cmdlets include:
"VMware1!"
-GuestToLocal -Source
c:\temp\logfile.txt
-Destination
c:\temp\
to simplify everyday tasks.
Remove-Datastore
Set-Folder
PowerCLI Reference: Automating vSphere
Set-Snapshot
Third-Party PowerCLI training from Pluralsight -
http://www.pluralsight.com
Administration
v2
VMware vSphere PowerCLI 5.8 Release 1 Reference Poster
PowerCLI Settings
Datacenter Operations
Cluster Operations
Guest OS
Host Operations
Network Operations
vCloud Tenant Operations
Dismount-Tools
Get-iScsiHbaTarget
Get-ScsiLunPath
Get-VDSwitch
Get-VirtualSwitch
Get-VMHostHba
Get-ErrorReport
Get-Datacenter
Get-Cluster
Get-CDDrive
Get-Template
New-CIAccessControlRule
Mount-Tools
New-iScsiHbaTarget
Set-ScsiLunPath
Get-VDSwitchPrivateVlan
New-VirtualSwitch
Set-VMHostHba
Get-DatastoreCluster
Get-PowerCLICommunity
Move-Datacenter
New-CDDrive
Move-Template
Remove-CIAccessControlRule
Update-Tools
Remove-iScsiHbaTarget
Get-SecurityPolicy
New-VDSwitch
Remove-VirtualSwitch
Get-VMHostNetwork
Get-PowerCLIConfiguration
New-Datacenter
Move-Cluster
Update Manager
Update Manager
Remove-CDDrive
Set-CIAccessControlRule
New-Template
Set-iScsiHbaTarget
Set-SecurityPolicy
New-VDSwitchPrivateVlan
Set-VirtualSwitch
Set-VMHostNetwork
Wait-Tools
Set-PowerCLIConfiguration
New-Cluster
Remove-Datacenter
Set-CDDrive
Remove-Template
Set-CINetworkAdapter
Get-VMGuest
Get-NicTeamingPolicy
Get-VDBlockedPolicy
Remove-VDSwitch
Add-VirtualSwitchPhysicalNetworkAdapter
Get-VMHostNetworkAdapter
vSphere
vCloud
Licensing
Get-PowerCLIDocumentation
Set-Datacenter
Remove-Cluster
Get-FloppyDrive
Set-CIVAppNetwork
Set-Template
Image
Set-NicTeamingPolicy
Get-VDPort
Remove-VDSwitchPhysicalNetworkAdapter
Remove-VirtualSwitchPhysicalNetworkAdapter
New-VMHostNetworkAdapter
Restart-VMGuest
Get-PowerCLIVersion
Set-Cluster
vSphere
vCloud
Licensing
New-FloppyDrive
Get-UsbDevice
Set-CIVAppStartRule
Get-OSCustomizationNicMapping
Export-VDPortGroup
Remove-VDSwitchPrivateVlan
Get-VMGuestNetworkInterface
Remove-
Shutdown-VMGuest
Builder
Remove-FloppyDrive
Remove-UsbDevice
Set-CIVAppTemplate
New-OSCustomizationNicMapping
Get-VDPortgroup
Remove-VDSwitchVMHost
Set-VMGuestNetworkInterface
VMHostNetworkAdapter
SRM
Suspend-VMGuest
Set-FloppyDrive
New-CIVApp
Get-VM
Remove-OSCustomizationNicMapping
New-VDPortgroup
Get-VDTrafficShapingPolicy
Get-VMGuestRoute
Set-VMHostNetworkAdapter
Copy-VMGuestFile
PowerCLI
Copy-HardDisk
Move-VM
Set-OSCustomizationNicMapping
Remove-VDPortGroup
Get-VDUplinkLacpPolicy
New-VMGuestRoute
Add-VmHostNtpServer
Remove-CIVApp
VMware vSphere Server
Get-VMGuestNetworkInterface
Get-HardDisk
Get-ScsiController
Get-VDPortgroupOverridePolicy
Get-VDUplinkTeamingPolicy
Remove-VMGuestRoute
Get-VMHostNtpServer
Restart-CIVApp
New-VM
Get-AdvancedSetting
Get-Datastore
Get-Task
Set-VMGuestNetworkInterface
New-ScsiController
Export-VDSwitch
Get-VirtualPortGroup
Get-VMHostFirewallDefaultPolicy
Remove-VMHostNtpServer
New-HardDisk
Restart-VM
Set-CIVApp
New-AdvancedSetting
Get-VMGuestRoute
Set-Datastore
Stop-Task
Set-ScsiController
Add-VDSwitchPhysicalNetworkAdapter
New-VirtualPortGroup
Set-VMHostFirewallDefaultPolicy
Test-VMHostSnmp
View
View
Remove-HardDisk
Remove-VM
Start-CIVApp
New-VMGuestRoute
Remove-AdvancedSetting
Copy-DatastoreItem
Wait-Task
Get-ScsiLun
Add-VDSwitchVMHost
Remove-VirtualPortGroup
Get-VMHostFirewallException
Get-VMHostSnmp
Auto
Image
Set-HardDisk
Set-VM
Stop-CIVApp
Set-AdvancedSetting
Get-VIAccount
Remove-VMGuestRoute
Set-ScsiLun
Get-VDSecurityPolicy
Set-VirtualPortGroup
Set-VMHostFirewallException
Set-VMHostSnmp
Apply-DrsRecommendation
Storage
New-NetworkAdapter
Start-VM
Suspend-CIVApp
Auto
Invoke-VMScript
Get-AlarmAction
Get-DrsRecommendation
Get-View
Deploy
Builder
PowerCLI
Remove-NetworkAdapter
Restart-CIVAppGuest
VSAN
STORAGE
Stop-VM
New-AlarmAction
Get-DrsRule
Get-VIObjectByVIView
Deploy
Set-NetworkAdapter
Suspend-VM
PowerShell for View Operations
Storage Policy Based Management
Stop-CIVAppGuest
Remove-AlarmAction
New-DrsRule
Get-VIPermission
Host Profiles
Add-PassthroughDevice
Open-VMConsoleWindow
New-CIVAppNetwork
Get-CompatibleStorage
Get-AlarmActionTrigger
Remove-DrsRule
New-VIPermission
Add-AutomaticPool
Get-GlobalSetting
Update-TerminalServerPool
Add-ManualUnmanagedPool
Get-PassthroughDevice
Get-VMQuestion
Remove-CIVAppNetwork
Apply-VMHostProfile
New-AlarmActionTrigger
Remove-VIPermission
Get-SpbmCapabilityMetadata
Set-DrsRule
Update-AutomaticPool
Update-GlobalSetting
Update-ManualUnmanagedPool
Get-RemoteSession
Remove-PassthroughDevice
Set-VMQuestion
Import-CIVAppTemplate
Export-VMHostProfile
Get-SpbmComplianceStatus
Remove-AlarmActionTrigger
Get-EsxCli
Set-VIPermission
Add-AutomaticLinkedClonePool
Get-License
Get-Monitor
Send-SessionDisconnect
Get-Snapshot
New-CIVAppTemplate
vCloud
Get-VMResourceConfiguration
vCloud
Get-VMHostProfile
Get-AlarmDefinition
Get-EsxTop
Get-VIPrivilege
Update-AutomaticLinkedClonePool
Set-License
Get-SpbmEntityConfiguration
Get-Pool
Send-SessionLogoff
New-Snapshot
Set-VMResourceConfiguration
Remove-CIVAppTemplate
Import-VMHostProfile
Set-SpbmEntityConfiguration
Set-AlarmDefinition
Move-Folder
New-VIProperty
Tenant
Tenant
Get-ComposerDomain
Send-LinkedCloneRebalance
Remove-Pool
Get-User
Remove-Snapshot
Get-VMStartPolicy
New-CIVM
PowerShell
New-VMHostProfile
New-SpbmRule
Get-Annotation
New-Folder
Remove-VIProperty
PowerShell
Get-ConnectionBroker
Send-LinkedCloneRecompose
Remove-UserOwnership
Add-PoolEntitlement
Set-Snapshot
Set-VMStartPolicy
Restart-CIVM
Remove-VMHostProfile
Set-Annotation
Get-VIRole
New-SpbmRuleSet
Get-Folder
Update-ConnectionBroker
Send-LinkedCloneRefresh
Get-PoolEntitlement
Update-UserOwnership
Start-CIVM
Set-VMHostProfile
New-SpbmStoragePolicy
Get-CustomAttribute
Remove-Folder
New-VIRole
Get-DesktopPhysicalMachine
Get-LocalSession
Remove-PoolEntitlement
Add-ViewVC
Stop-CIVM
Test-VMHostProfileCompliance
New-CustomAttribute
Set-Folder
Remove-VIRole
Get-DesktopVM
Send-LocalSessionRollback
Set-SpbmStoragePolicy
Get-ProfileDisk
Get-ViewVC
Suspend-CIVM
Get-SpbmStoragePolicy
Remove-CustomAttribute
Get-Inventory
Set-VIRole
Get-EventReport
Add-ManualPool
Get-TerminalServer
Remove-ViewVC
Restart-CIVMGuest
Remove-SpbmStoragePolicy
Set-CustomAttribute
Move-Inventory
Connect-VIServer
Get-EventReportList
Update-ManualPool
Auto Deploy Operations
Licensing Operations
vCenter Update Manager
Add-TerminalServerPool
Update-ViewVC
Stop-CIVMGuest
New-Datastore
Disconnect-VIServer
Virtual Machine Host Operations
Get-SpbmView
Remove-Inventory
Send-VMReset
Search-Cloud
Switch-ActiveDeployRuleSet
Export-StorageProfile
Remove-Datastore
Get-NetworkAdapter
Set-Org
Get-HAPrimaryVMHost
Get-VMHostAccount
Get-LicenseDataManager
Get-VMHostDisk
Get-VMHostRoute
Repair-DeployImageCache
Get-VMHostStartPolicy
Import-StorageProfile
Add-VMHost
New-VMHostAccount
Attach-Baseline
Set-PowerCLIConfiguration
Format-VMHostDiskPartition
New-VMHostRoute
Add-DeployRule
Set-VMHostStartPolicy
vCloud Operations
Get-PowerCLIVersion
Get-VMHost
Set-VMHostAccount
Detach-Baseline
Get-VMHostDiskPartition
Remove-VMHostRoute
Get-VMHostSysLogServer
Copy-DeployRule
Logs/Reporting/Configuration
vApps
Move-VMHost
Remove-VMHostAccount
Get-Baseline
Get-Task
Get-VMHostFirmware
Set-VMHostRoute
Get-DeployRule
Image Builder Operations
Set-VMHostSysLogServer
Connect-CIServer
Get-CIUser
Set-CIVAppNetwork
Start-CIVM
Get-Org
Resource Pool Operations
Get-VMHostAdvancedConfiguration
Remove-Baseline
Tags
Stop-Task
Remove-VMHost
Set-VMHostFirmware
Get-VMHostService
Get-ErrorReport
New-DeployRule
Disconnect-CIServer
Start-CIVApp
Get-CIVAppNetwork
Stop-CIVM
Set-StatInterval
Compare-EsxImageProfile
Remove-Org
Export-vApp
Wait-Task
Restart-VMHost
Set-VMHostAdvancedConfiguration
Get-Compliance
Get-ResourcePool
Get-VMHostModule
Restart-VMHostService
Remove-DeployRule
Get-Catalog
Import-CIVApp
Remove-CIVAppNetwork
Get-Log
Get-StatType
Export-EsxImageProfile
Restart-CIVM
Set-Org
Get-Tag
Get-vApp
Set-VMHost
Get-VMHostAuthentication
Download-Patch
Get-VICredentialStoreItem
Set-VMHostModule
Set-VMHostService
Set-DeployRule
Get-CIAccessControlRule
New-CIVApp
Move-ResourcePool
Get-LogType
New-CIVAppNetwork
New-CIVM
New-Org
Get-VICredentialStoreItem
Get-EsxImageProfile
New-Tag
Import-vApp
New-VICredentialStoreItem
Start-VMHost
Set-VMHostAuthentication
Get-Patch
Set-CIAccessControlRule
Restart-CIVApp
New-ResourcePool
Get-OSCustomizationSpec
Get-VMHostPatch
Start-VMHostService
Get-DeployRuleSet
Set-CIVAppStartRule
Get-CIVM
New-OrgVdc
New-VICredentialStoreItem
New-EsxImageProfile
Remove-Tag
Move-Vapp
Stop-VMHost
Get-VMHostAvailableTimeZone
Stage-Patch
New-CIAccessControlRule
Remove-CIVApp
Remove-VICredentialStoreItem
Install-VMHostPatch
Stop-VMHostService
Set-DeployRuleSet
Get-CIVAppStartRule
Suspend-CIVM
Remove-OrgVdc
Remove-ResourcePool
New-OSCustomizationSpec
Set-Tag
Remove-VICredentialStoreItem
Set-EsxImageProfile
New-vApp
Get-VMHostDiagnosticPartition
Get-PatchBaseline
Remove-CIAccessControlRule
Set-CIVApp
Suspend-VMHost
Get-VMHostProfileRequiredInput
Import-CIVAppTemplate
Stop-CIVMGuest
Set-OrgVdc
Remove-OSCustomizationSpec
Get-VMHostStorage
Repair-DeployRuleSetCompliance
Set-ResourcePool
Get-TagAssignment
Get-VMHostSysLogServer
Get-EsxSoftwareChannel
Remove-vApp
Add-CIDatastore
Stop-CIVApp
Set-VMHostDiagnosticPartition
New-PatchBaseline
Remove-CIVAppTemplate
Restart-CIVMGuest
Get-OrgVdc
Set-VMHostStorage
Test-DeployRuleSetCompliance
New-TagAssignment
Set-OSCustomizationSpec
Set-VMHostSysLogServer
Add-EsxSoftwareDepot
Get-CIDatastore
Suspend-CIVApp
Set-vApp
Set-PatchBaseline
Set-CIVAppTemplate
Search-Cloud
Get-ProviderVdc
Apply-ESXImageProfile
Remove-TagAssignment
Get-Stat
Get-VMResourceConguration
Remove-EsxSoftwareDepot
Set-CINetworkAdapter
Get-CIVApp
OVF Configuration
Site Recovery Manager
Start-vApp
Get-CIVAppTemplate
Get-ExternalNetwork
Get-OrgNetwork
Remediate-Inventory
Get-TagCategory
Get-VMHostAttributes
Get-StatInterval
Get-VIEvent
Add-EsxSoftwarePackage
Get-CINetworkAdapter
Stop-CIVAppGuest
New-CIVAppTemplate
Get-Media
Remove-OrgNetwork
Stop-vApp
Scan-Inventory
New-TagCategory
Get-VMHostImageProfile
Connect-SrmServer
New-StatInterval
Get-CIRole
Get-VIProperty
Get-EsxSoftwarePackage
Restart-CIVAppGuest
Get-CIView
Get-NetworkPool
Set-OrgNetwork
Get-OVFConfiguration
Remove-TagCategory
Disconnect-SrmServer
Remove-StatInterval
Get-VMHostMatchingRules
New-VIProperty
Remove-EsxSoftwarePackage
New-OrgNetwork
Set-TagCategory
VMware vSphere PowerCLI Quick Reference Examples
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Getting Started
Virtual Switch Operations
Task Information
vApp Operations
ESXTOP through PowerCLI
Quick Helpful Commands
Leverage Jobs for Multi-threaded Operations
Image Builder
VMware vSphere PowerCLI frequently asked questions (FAQs) link:
To list all virtual switches attached to a VM and some of their properties, use:
The following is a list of vApp cmdlets; use the Get-Help function for example uses:
Get-EsxTop –Counter
Top 5 VM memory allocation:
Jobs allow users to run scripts in parallel.
Connect to a depot:
To list all tasks for a VMware vSphere server and some of their properties:
http://communities.vmware.com/docs/DOC-13700
New-vApp -Name
MyvApp
-CpuLimitMhz
4000
-CpuReservationMhz
1000
-Location
# View the fields available for vCPU counter:
Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
Get-VirtualSwitch -VM (Get-VM -Name
"Lync-Edge-03")
Get-Task
Get-VM
|
Sort-Object -Property
MemoryGB
-Descending
|
Select -
Create a script that will be run in a job:
To find out what cmdlets are available:
Get-VICommand
To create a new virtual switch:
To stop a task (example: stops the task of removing the VM):
(Get-VMHost
MyHost)
(Get-EsxTop –Counter
–CounterName
VCPU).Fields
First
5
$jobscript
=
{
Add a package by name to an image profile:
To show documentation for all available cmdlets:
Get-PowerCLIDocumentation
New-VirtualSwitch -VMHost (Get-VMHost -Name
192.168.0.10) -Name
Switch02
Get-EsxTop –TopologyInfo
# Add PowerCLI Snapin
Add-EsxSoftwarePackage -ImageProfile "My custom profile" -SoftwarePackage net-bnx2
Stop-Task -Task (Remove-VM -VM
"Lync-Edge-03"
-Confirm
-RunAsync)
Other vApp cmdlets:
Remove-vApp
To remove a virtual switch:
# View the entries of a specific topology:
Clone an image profile, then add a package by name:
For help with a cmdlet:
Get-Help
cmdlet-name
–Full
To wait until a task is completed before continuing:
Add-PSSnapin
VMware.VimAutomation.core
Export-vApp
Total memory available on all ESXi:
Set-vApp
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
VS23
(Get-EsxTop –TopologyInfo
–Topology
SchedGroup).Entries | FT
# Connect to vCenter
New-EsxImageProfile -CloneProfile "ESX-5.0-234567-standard" -Name "My custom profile" | Add-EsxSoftwarePackage net-bnx2
Wait-Task -Task (Remove-VM -VM
"Lync-Edge-03"
-Confirm
-RunAsync)
Get-VMHost
|
Measure-Object -Property
MemoryTotalGB
-Sum
|
Get-vApp
Start-vApp
Remove-VirtualSwitch -VirtualSwitch
$vs
# Retrieve the counter values for “VCPU” and “SchedGroup" counters:
Connect-VIserver
vcsa.lab.local
-User
root
-Password
"VMware1!"
Export an ISO image
Import-vApp
Stop-vApp
Select -ExpandProperty
Sum
How to Connect to vCenter Server or ESXi
To change the configuration of a virtual switch:
Get-EsxTop –CounterName VCPU
| FT * -AutoSize
# Create Snapshots of all LabTest VM's
Export-EsxImageProfile -ImageProfile "Evan's Profile" -ExportToIso -FilePath c:\isos\evans-iso.iso
$vs =
New-VirtualSwitch -Host
192.168.0.10
-Name
VirtSwitch
Get-EsxTop –CounterName SchedGroup
| FT * -AutoSize
Get-VM
"LABTEST*"
|
New-Snapshot -Name
InitialSnapshot}
Clone an image profile, add a software package, then export to offline bundle.
Tag Operations
Report on NumCPU and number of VM:
To connect to a VMware vSphere server. Start a new session or reestablish a
New-EsxImageProfile -CloneProfile "ESXi-5.0.0-234567-standard" -Name "Evan's Profile"
Set-VirtualSwitch -VirtualSwitch
$vs
-MTU
500
previous session with a VMware vSphere server.
Get-VM
|
Group-Object -Property
NumCpu
|
To start the Job:
Add-EsxSoftwarePackage -ImageProfile "Evan's Profile" -SoftwarePackage cisco-vem-v140
Create a tag category:
OVF Configuration
Export-EsxImageProfile -ImageProfile "Evan's Profile" -ExportToBundle -FilePath c:\isos\base-plus-vem.zip
$srv =
Connect-VIServer –Server
192.168.0.10
-User
Admin
-Password
Pass01
Select
@{N="NumCpu";E={$_.Name}},@{N="Number of
Start-Job -Name
Snapshots
-ScriptBlock
$jobscript
Port Group Operations
New-TagCategory -Name
"Owner"
-Cardinality
Single
-EntityType
To disconnect from the connected vSphere server:
VM";E={$_.Count}}
Display all image profiles from depots and all image profiles the user created during this PowerCLI session:
Resource Pool Operations
VirtualMachine
Using OVFConfiguration to deploy vApps:
When Jobs are running you can use
Get-Job
to see the status:
Get-EsxImageProfile
Disconnect-VIServer -Server
$srv -Confirm:$false
To list all the port groups and some of their properties:
$ovfconfig
=
get-OvfConfiguration
“myOvfTemplate.ovf”
Remove-TagCategory
"Owner"
List all the VIBs, sorted by date:
Get-Job
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
Switch02
Most API methods require parameters.
To list all resource pools on the connected VMware vSphere server and some of
Create a tag:
$ovfconfig.ToHashtable()
Get-Job -Name
Snapshots
Get-EsxSoftwarePackage | Sort-Object ReleaseDate | Format-Table -Property Name,Version,Vendor
Get-VirtualPortGroup -VirtualSwitch
$vs
You create those with New-Object:
their properties:
Get-ResourcePool
$myTag =
New-Tag -Name
"jSmith"
-Category
"Owner"
Get-Job -Id
1
List all the VIBs from VMware and Cisco released after Jan 1, 2010:
How to Connect to SRM
To add a new port group to a virtual switch:
Use a hashtable:
$vm
=
Get-VM -Name
MyVM
Assign a tag:
Get-EsxSoftwarePackage -Vendor "VMware","Cisco" -ReleasedAfter 1/1/2010
$vs =
Get-VirtualSwitch -VMHost
192.168.0.10
-Name
Switch02
To create a new resource pool:
$ovfconfig
=
@{
$spec
=
New-Object
VMware.Vim.VirtualMachineConfigSpec
Get-VM -Name
"Lync-Edge-*"
|
New-TagAssignment -Tag
$myTag
You can stop a job manually:
List all the VIBs from vendors other than VMware
Connect to vCenter Server first
$vpg =
New-VirtualPortGroup -VirtualSwitch
$vs
-Name
VPG1
$clusterRootRP
=
Get-ResourcePool -Location
"vami.DNS.VMware_vCenter_Log_Insight"
=
"10.144.99.5";
$spec.latencySensitivity
=
New-Object
Get-VM -Tag
"jSmith"
Get-Job -Name
Snapshots
|
Stop-Job
Get-EsxSoftwarePackage | ? {$_.Vendor -ne "VMware"}
Other cmdlets include:
Connect-SrmServer -SrmServerAddress
10.144.99.6
-User
(Get-Cluster
ResearchAndDevelopmentCluster
) -Name Resources
"vami.gateway.VMware_vCenter_Log_Insight"
=
"10.144.99.1";
VMware.Vim.LatencySensitivity
Clone an image profile, give it a new name, and change the acceptance level.
"administrator"
-Password
"myPassword"
"vami.ip0.VMware_vCenter_Log_Insight"
=
"10.144.99.30";
Remove-VirtualPortGroup
New-ResourcePool -Location
$clusterRootRP
-Name
DevelopmentResources
New-EsxImageProfile -CloneProfile "ESX-5.0-234567-standard" -Name "My custom profile" -AcceptanceLevel CommunitySupported
$spec.LatencySensitivity.Level
=
To see the results of the script you can receive the job
Set-VirtualPortGroup
-CpuExpandableReservation
$true
-CpuReservationMhz
"vami.netmask0.VMware_vCenter_Log_Insight"
=
"255.255.255.0";
Disconnect-SrmServer -Server
10.144.99.6
[VMware.Vim.LatencySensitivitySensitivityLevel]::high
use the
-Keep
parameter to allow this information to stay:
Connect to a depot, then disconnect from it by URL.
500
-CpuSharesLevel
high
-MemExpandableReservation
$true
"vm.rootpw"
=
"VMware1!";}
Get-Job -Name
Snapshots
|
Receive-Job -Keep
Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
$vm.ExtensionData.reReconfigVM($spec)
-MemReservationMB
500
-MemSharesLevel
high
Remove package foo from my custom profile:
Managing Events Alarms
When finished with a job you may remove it:
API Operations
Or populate an object:
Get-Job -Name
Snapshots
|
Remove-Job
Remove-EsxSoftwarePackage -ImageProfile "My custom profile" -SoftwarePackage foo
Other resource pool cmdlets:
$ovfconfig.NetworkMapping.Network.Value =
“Network
1”
Modify the VIB list of an existing image profile
Get-AlarmDefinition
# Returns all the defined alarms on the servers
Move-ResourcePool
$ovfconfig.vami.VM_1.ip0.Value = “10.144.99.30”
How to Store vCenter Credentials
Returns a VMware vSphere.Net view object by specified search
you’re connected to.
Set-EsxImageProfile -ImageProfile "Profile of a Fool" -SoftwarePackage esx-base,scsi-ips,esx-tboot
Remove-ResourcePool
$ovfPath
= “c:\temp\myOvfTemplate.ovf”
criteria.
Get-AlarmDefinition -Name "virtual machine*"
-Enabled $false
Set-ResourcePool
Snapshot Operations
PowerCLI Info
$vm =
Get-View -ViewType
VirtualMachine
-Filter
@{"Name" = "MS
Method to not have to input credentials every time you connect to
# Returns all the disabled alarm definitions with names starting with
Import-Vapp
$ovfPath
-OvfConfiguration
$ovfConfig
-VMHost
$vmHost
-Name
“VM_OVF”
vCenter:
Win XP
SP2"}
“virtual machine.”
Datastore Operations
Folder Operations
To list all the snapshots for all virtual machines:
PowerCLI Sites
PowerCLI Books
$hostView =
Get-View -ID
$vm.Runtime.Host
Get-VMHost hostname
|
Get-AlarmDefinition
# Returns all alarms that
New-VICredentialStoreItem -Host
vCSA.lab.local
-User
Root
-
Get-VM
|
Get-Snapshot
Copy Files To/From VM
What is PowerCLI?
$hostView.Summary.Runtime
apply to the host “hostname”. Includes alarms defined on this host and
For a list of datastores and other
The following is a list of all folder-
Password
"VMware1!"
To snapshot a VM:
Official PowerCLI Blog -
http://blogs.vmware.com/PowerCLI/
Learning PowerCLI
Another example:
alarms inherited from the parent entity, or from any ancestors in the
properties:
related cmdlets:
New-Snapshot
-VM "XP SP2"
-Name
BeforePatch1
To remove credentials:
Invoke Commands In Virtual Machines
Documentation -
http://vmware.com/support/developer/PowerCLI /index.html
inventory hierarchy.
Get-Datastore
Get-Folder
VMware vSphere PowerCLI is a powerful,
(Get-View (Get-VMHost
'ESX1'
|
get-view).ConfigManager
Remove-VICredentialStoreItem -Host
vCSA.lab.local
-Confirm
Files can be copied between user’s local machine and a VM
To remove a snapshot:
VMware PowerCLI Community -
http://vmware.com/go/powercli
easy-to-use scripting interface to manage
Managing VMware Infrastructure with Windows
.VmotionSystem).SelectVnc('vmk0')
Modify an alarm definition:
Get-AlarmDefinition
"Host memory status" |
Move-Folder
Remove-Snapshot -Snapshot
$snapshot1
Twitter -
https://twitter.com/PowerCLI
Copy from a VM to the Local Machine:
Invoke-VMScript
allows BIN, BASH, and Powershell Commands to be invoked remotely
the vSphere platform. Administrators can
Set-AlarmDefinition -Name "Host memory"
-Enabled $false
Other datastore cmdlets include:
New-Folder
PowerShell TFM
API Reference:
RemoveChildren
LinkedIn -
http://www.linkedin.com/groups/PowerCLI-Users-162324
Copy-VMGuestFile -VM
LABTEST1
-GuestUser
Administrator
-GuestPassword
Invoke-VMScript -VM
LABTEST1
-ScriptText
"dir"
-GU
Administrator
-GP
"VMware1!"
New-Datastore
Remove-Folder
Leverage more than 360 cmdlets
https://www.vmware.com/support/developer/vc-sdk/
# This will rename the alarm to “Host memory” and disable it.
Facebook -
https://www.facebook.com/vmwarepowercli
Other cmdlets include:
"VMware1!"
-GuestToLocal -Source
c:\temp\logfile.txt
-Destination
c:\temp\
to simplify everyday tasks.
Remove-Datastore
Set-Folder
PowerCLI Reference: Automating vSphere
Set-Snapshot
Third-Party PowerCLI training from Pluralsight -
http://www.pluralsight.com
Administration
v2