VMware vSphere PowerCLI 6.3 Release 1 Reference Poster · VMware vSphere PowerCLI Quick Reference...

Post on 25-May-2018

281 views 5 download

Transcript of VMware vSphere PowerCLI 6.3 Release 1 Reference Poster · VMware vSphere PowerCLI Quick Reference...

VMware vSphere PowerCLI Quick Reference Examples

Get-ErrorReportGet-PowerCLIConfigurationSet-PowerCLIConfiguration

Get-PowerCLIVersion

PowerCLI Settings

Get-AdvancedSettingNew-AdvancedSetting

Remove-AdvancedSettingSet-AdvancedSetting

Get-AlarmActionNew-AlarmAction

Remove-AlarmActionGet-AlarmActionTrigger

New-AlarmActionTriggerRemove-AlarmActionTrigger

Get-AlarmDefinitionSet-AlarmDefinition

Get-AnnotationSet-Annotation

Get-ContentLibraryItemGet-CustomAttribute

New-CustomAttributeRemove-CustomAttribute

Set-CustomAttributeGet-Datastore

Move-DatastoreNew-Datastore

Remove-DatastoreSet-Datastore

Get-DatastoreClusterNew-DatastoreCluster

Remove-DatastoreClusterSet-DatastoreClusterCopy-DatastoreItem

Get-DrsRecommendationInvoke-DrsRecommendation

Get-DrsRuleNew-DrsRule

Remove-DrsRuleSet-DrsRule

Get-EsxCliGet-EsxTopGet-Folder

Move-FolderNew-Folder

Remove-FolderSet-Folder

Get-InventoryMove-Inventory

Remove-InventoryGet-OvfConfiguration

Get-TaskStop-TaskWait-Task

Get-VIAccountGet-View

Get-VIObjectByVIViewGet-VIPermission

New-VIPermissionRemove-VIPermission

Set-VIPermissionGet-VIPrivilegeGet-VIProperty

New-VIPropertyRemove-VIProperty

Get-VIRoleNew-VIRole

Remove-VIRoleSet-VIRole

Connect-VIServerDisconnect-VIServer

VMware vSphere Server

Set-DatacenterGet-Datacenter

Move-DatacenterNew-Datacenter

Remove-Datacenter

Datacenter Operations

Get-ClusterMove-ClusterNew-Cluster

Remove-ClusterSet-Cluster

Get-DrmInfo

Cluster Operations

Dismount-ToolsMount-Tools

Update-ToolsWait-Tools

Get-VMGuestRestart-VMGuest

Stop-VMGuestSuspend-VMGuestCopy-VMGuestFile

Get-VMGuestNetworkInterfaceSet-VMGuestNetworkInterface

Get-VMGuestRouteNew-VMGuestRoute

Remove-VMGuestRouteInvoke-VMScript

Guest OS

Switch-ActiveDeployRuleSetRepair-DeployImageCache

Add-DeployRuleCopy-DeployRule

Get-DeployRuleNew-DeployRule

Remove-DeployRuleSet-DeployRule

Get-DeployRuleSetSet-DeployRuleSet

Repair-DeployRuleSetComplianceTest-DeployRuleSetCompliance

Get-VMHostImageProfileGet-VMHostMatchingRules

Auto Deploy Operations

Attach-BaselineDetach-Baseline

Get-BaselineRemove-BaselineGet-ComplianceTest-Compliance

Update-EntityAdd-EntityBaseline

Remove-EntityBaselineCopy-Patch

Download-PatchGet-Patch

Stage-PatchSync-Patch

Get-PatchBaselineNew-PatchBaselineSet-PatchBaseline

Scan-InventoryRemediate-Inventory

vCenter Update Manager

Get-OMAlertSet-OMAlert

Get-OMAlertDefinitionGet-OMAlertSubType

Get-OMAlertTypeGet-OMRecommendation

Get-OMResourceConnect-OMServer

Disconnect-OMServerGet-OMStat

Get-OMStatKeyGet-OMUser

vRealize Operations

Apply-ESXImageProfileCompare-EsxImageProfile

Export-EsxImageProfileGet-EsxImageProfile

New-EsxImageProfileSet-EsxImageProfile

Remove-EsxImageProfileAdd-EsxSoftwareDepotGet-EsxSoftwareDepot

Remove-EsxSoftwareDepotAdd-EsxSoftwarePackageGet-EsxSoftwarePackage

Remove-EsxSoftwarePackage

Image Builder Operations

Export-VMHostProfileGet-VMHostProfile

Import-VMHostProfileInvoke-VMHostProfile

New-VMHostProfileRemove-VMHostProfile

Set-VMHostProfileTest-VMHostProfileCompliance

Get-VMHostProfileRequiredInput

Host Profiles

Get-IScsiHbaTargetNew-IScsiHbaTarget

Remove-IScsiHbaTargetSet-IScsiHbaTarget

Get-NfsUserNew-NfsUser

Remove-NfsUserSet-NfsUser

Get-ScsiControllerNew-ScsiControllerSet-ScsiController

Get-ScsiLunSet-ScsiLun

Get-ScsiLunPathSet-ScsiLunPath

Get-SpbmCapabilityGet-SpbmCompatibleStorageGet-SpbmEntityConfigurationSet-SpbmEntityConfiguration

New-SpbmRuleNew-SpbmRuleSet

Export-SpbmStoragePolicyGet-SpbmStoragePolicy

Import-SpbmStoragePolicyNew-SpbmStoragePolicy

Remove-SpbmStoragePolicySet-SpbmStoragePolicy

Get-VAIOFilterNew-VAIOFilter

Remove-VAIOFilterSet-VAIOFilter

Get-VasaProviderNew-VasaProvider

Remove-VasaProviderGet-VasaStorageArray

Storage Operations

Get-ResourcePoolMove-ResourcePoolNew-ResourcePool

Remove-ResourcePoolSet-ResourcePool

Resource Pool Operations

Connect-SrmServerDisconnect-SrmServer

Site Recovery Manager

Get-VsanDiskNew-VsanDisk

Remove-VsanDiskGet-VsanDiskGroup

New-VsanDiskGroupRemove-VsanDiskGroup

VSAN Operations

Get-OVFConfiguration

OVF Configuration

Get-MirageAppLayerGet-MirageAssignment

Invoke-MirageAssignmentGet-MirageBaseLayerDismount-MirageCvd

Get-MirageCvdNew-MirageCvd

Remove-MirageCvdReset-MirageCvd

Restart-MirageCvdSet-MirageCvd

Sync-MirageCvdSet-MirageCvdAppLayerGet-MirageCvdCollection

Get-MirageOsMigrationInvoke-MirageOsMigration

New-MirageOsMigrationGet-MiragePendingDevice

Get-MiragePolicyConnect-MirageServer

Disconnect-MirageServerGet-MirageVolume

Mirage Operations

Get-TagNew-Tag

Remove-TagSet-Tag

Get-TagAssignmentNew-TagAssignment

Remove-TagAssignmentGet-TagCategory

New-TagCategoryRemove-TagCategory

Set-TagCategory

Tags

Get-LogGet-LogType

Get-OSCustomizationNicMappingNew-OSCustomizationNicMapping

Remove-OSCustomizationNicMappingSet-OSCustomizationNicMapping

Get-OSCustomizationSpecNew-OSCustomizationSpec

Remove-OSCustomizationSpecSet-OSCustomizationSpec

Get-StatGet-StatInterval

New-StatIntervalRemove-StatInterval

Set-StatIntervalGet-StatType

Get-VICredentialStoreItemNew-VICredentialStoreItem

Remove-VICredentialStoreItemGet-VIEvent

Logs/Reporting/Configuration

Get-CDDriveNew-CDDrive

Remove-CDDriveSet-CDDrive

Get-FloppyDriveNew-FloppyDrive

Remove-FloppyDriveSet-FloppyDrive

Copy-HardDiskGet-HardDisk

Move-HardDiskNew-HardDisk

Remove-HardDiskSet-HardDisk

Get-NetworkAdapterNew-NetworkAdapter

Remove-NetworkAdapterSet-NetworkAdapter

Add-PassthroughDeviceGet-PassthroughDevice

Remove-PassthroughDeviceGet-Snapshot

New-Snapshot

Remove-SnapshotSet-SnapshotGet-Template

Move-TemplateNew-Template

Remove-TemplateSet-Template

Get-UsbDeviceRemove-UsbDevice

Get-VMMove-VMNew-VM

Remove-VMRestart-VM

Set-VMStart-VMStop-VM

Suspend-VMOpen-VMConsoleWindow

Get-VMQuestionSet-VMQuestion

Get-VMResourceConfigurationSet-VMResourceConfiguration

Virtual Machine Operations

Export-VAppGet-VApp

Import-VAppMove-VAppNew-VApp

Remove-VAppSet-VApp

Start-VAppStop-VApp

vApps

Get-HAPrimaryVMHostAdd-VMHostGet-VMHost

Move-VMHostRemove-VMHostRestart-VMHost

Set-VMHostStart-VMHostStop-VMHost

Suspend-VMHostGet-VMHostAccount

New-VMHostAccountRemove-VMHostAccount

Set-VMHostAccountGet-VMHostAdvancedConfigurationSet-VMHostAdvancedConfiguration

Get-VMHostAttributes

Get-VMHostAuthenticationSet-VMHostAuthentication

Get-VMHostAvailableTimeZoneGet-VMHostDiagnosticPartitionSet-VMHostDiagnosticPartition

Get-VMHostDiskFormat-VMHostDiskPartition

Get-VMHostDiskPartitionGet-VMHostFirewallDefaultPolicySet-VMHostFirewallDefaultPolicy

Get-VMHostFirewallExceptionSet-VMHostFirewallException

Get-VMHostFirmwareSet-VMHostFirmwareGet-VMHostHardware

Get-VMHostHbaSet-VMHostHba

Get-VMHostModuleSet-VMHostModule

Get-VMHostNetworkSet-VMHostNetwork

Get-VMHostNetworkAdapterNew-VMHostNetworkAdapter

Remove-VMHostNetworkAdapterSet-VMHostNetworkAdapter

Add-VMHostNtpServerGet-VMHostNtpServer

Remove-VMHostNtpServerGet-VMHostPatch

Install-VMHostPatchGet-VMHostPciDevice

Get-VMHostRouteNew-VMHostRoute

Remove-VMHostRouteSet-VMHostRoute

Get-VMHostServiceRestart-VMHostService

Set-VMHostServiceStart-VMHostServiceStop-VMHostService

Get-VMHostSnmpSet-VMHostSnmp

Test-VMHostSnmpGet-VMHostStartPolicySet-VMHostStartPolicy

Get-VMHostStorageSet-VMHostStorage

Get-VMHostSysLogServerSet-VMHostSysLogServer

Get-VMStartPolicySet-VMStartPolicy

ESXi Host Operations

Get-NicTeamingPolicySet-NicTeamingPolicy

Get-SecurityPolicySet-SecurityPolicy

Get-VDBlockedPolicySet-VDBlockedPolicy

Get-VDPortSet-VDPort

Export-VDPortGroupGet-VDPortgroup

New-VDPortgroupRemove-VDPortGroup

Set-VDPortgroupGet-VDPortgroupOverridePolicySet-VDPortgroupOverridePolicy

Get-VDSecurityPolicySet-VDSecurityPolicy

Export-VDSwitchGet-VDSwitch

New-VDSwitchRemove-VDSwitch

Set-VDSwitchAdd-VDSwitchPhysicalNetworkAdapter

Remove-VDSwitchPhysicalNetworkAdapter

Get-VDSwitchPrivateVlanNew-VDSwitchPrivateVlan

Remove-VDSwitchPrivateVlanAdd-VDSwitchVMHost

Remove-VDSwitchVMHostGet-VDTra�cShapingPolicySet-VDTra�cShapingPolicy

Get-VDUplinkLacpPolicySet-VDUplinkLacpPolicy

Get-VDUplinkTeamingPolicySet-VDUplinkTeamingPolicy

Set-VDVlanConfigurationGet-VirtualPortGroup

New-VirtualPortGroupRemove-VirtualPortGroup

Set-VirtualPortGroupGet-VirtualSwitch

New-VirtualSwitchRemove-VirtualSwitch

Set-VirtualSwitchAdd-VirtualSwitchPhysicalNetworkAdapter

Remove-VirtualSwitchPhysicalNetworkAdapter

Network Operations

Add-AutomaticPoolUpdate-AutomaticPool

Add-AutomaticLinkedClonePoolUpdate-AutomaticLinkedClonePool

Get-ComposerDomainGet-ConnectionBroker

Update-ConnectionBrokerGet-DesktopPhysicalMachine

Get-DesktopVMGet-EventReport

Get-EventReportList

Get-GlobalSettingUpdate-GlobalSetting

Get-LicenseSet-License

Send-LinkedCloneRebalanceSend-LinkedCloneRecompose

Send-LinkedCloneRefreshGet-LocalSession

Send-LocalSessionRollbackAdd-ManualPool

Update-ManualPool

Add-ManualUnmanagedPoolUpdate-ManualUnmanagedPool

Get-MonitorGet-Pool

Remove-PoolAdd-PoolEntitlementGet-PoolEntitlement

Remove-PoolEntitlementGet-ProfileDisk

Get-TerminalServerAdd-TerminalServerPool

Update-TerminalServerPoolGet-RemoteSession

Send-SessionDisconnectSend-SessionLogo�

Get-UserRemove-UserOwnershipUpdate-UserOwnership

Add-ViewVCGet-ViewVC

Remove-ViewVCUpdate-ViewVCSend-VMReset

PowerShell for View Operations

Get-CatalogGet-CIAccessControlRule

New-CIAccessControlRuleRemove-CIAccessControlRule

Set-CIAccessControlRuleAdd-CIDatastoreGet-CIDatastore

Get-CINetworkAdapterSet-CINetworkAdapter

Get-CIRoleConnect-CIServer

Connect-CisServerDisconnect-CIServer

Disconnect-CisServerGet-CisService

Get-CIUserGet-CIVApp

Import-CIVAppNew-CIVApp

Remove-CIVAppRestart-CIVApp

Set-CIVAppStart-CIVAppStop-CIVApp

Suspend-CIVAppRestart-CIVAppGuest

Stop-CIVAppGuestSuspend-CIVAppGuest

Get-CIVAppNetworkNew-CIVAppNetwork

Remove-CIVAppNetworkSet-CIVAppNetwork

Get-CIVAppStartRuleSet-CIVAppStartRule

Get-CIVAppTemplateImport-CIVAppTemplate

New-CIVAppTemplateRemove-CIVAppTemplate

Set-CIVAppTemplateGet-CIView

Get-CIVMNew-CIVM

Restart-CIVMStart-CIVMStop-CIVM

Suspend-CIVMRestart-CIVMGuest

Stop-CIVMGuestGet-CIVMTemplate

Search-CloudGet-CloudCommand

Get-ExternalNetworkGet-Media

Get-NetworkPoolGet-Org

New-OrgRemove-Org

Set-OrgGet-OrgNetwork

New-OrgNetworkRemove-OrgNetwork

Set-OrgNetworkGet-OrgVdc

New-OrgVdcRemove-OrgVdc

Set-OrgVdcGet-OrgVdcNetwork

Get-ProviderVdc

vCloud Operations

PowerShell

PowerCLI

vSphere

SRM

Auto Deploy Image Builder

Licensing vCloud vROps

Update Manager VSAN

HA Storage vCloud Air View

Mirage

WEM

Get-LicenseDataManager

Licensing Operations

Top 5 VM memory allocation:Get-VM | Sort-Object -Property MemoryGB -Descending | Select-First 5

Total memory available on all ESXi:Get-VMHost | Measure-Object -Property MemoryTotalGB -Sum |Select -ExpandProperty Sum

Report on NumCPU and number of VM:Get-VM | Group-Object -Property NumCpu |Select @{N="NumCpu";E={$_.Name}},@{N="Number ofVM";E={$_.Count}}

Most API methods require parameters.You create those with New-Object:$vm = Get-VM -Name MyVM$spec = New-Object VMware.Vim.VirtualMachineConfigSpec$spec.latencySensitivity = New-ObjectVMware.Vim.LatencySensitivity$spec.LatencySensitivity.Level =[VMware.Vim.LatencySensitivitySensitivityLevel]::high$vm.ExtensionData.reReconfigVM($spec)

Quick Helpful Commands

For a list of datastores and otherproperties:Get-Datastore

Other datastore cmdlets include:New-DatastoreRemove-Datastore

Datastore Operations

The following is a list of all folder-related cmdlets:Get-FolderMove-FolderNew-FolderRemove-FolderSet-Folder

Folder Operations

To list all of the VSAN disks groups for an ESXi host:Get-VsanDiskGroup -VMHost (Get-VMHost | select -first 1)

To list all of the disks within a VSAN disk group for an ESXi host:$vmhost = Get-VMHost | select -First 1$vsanDiskGroup = Get-VsanDiskGroup -VMHost $vmhostGet-VsanDisk -VsanDiskGroup $vsanDiskGroup

To create a new VSAN disk group for an ESXi host$vmhost = Get-VMHost | select -First 1$ssd = Get-ScsiLun -VmHost $vmhost | where {$_.extensiondata.ssd -eq $true -and$_.ExtensionData.LocalDisk -eq $true}$datadisk = Get-ScsiLun -VmHost $vmhost | where {$_.extensiondata.ssd -eq $false -and $_.ExtensionData.LocalDisk -eq $true}New-VsanDiskGroup -VMHost $vmhost -SsdCanonicalName $ssd.CanonicalName -DataDiskCanonicalName $datadisk.CanonicalName

To remove a disk from a VSAN disk group:$vmhost = Get-VMHost | select -First 1$vsanDiskGroup = Get-VsanDiskGroup -VMHost $vmhost$vsanDisk = Get-VsanDisk -VsanDiskGroup $vsanDiskGroup | select -first 1Remove-VsanDisk -VsanDisk $vsanDisk

VSAN Operations

Utilizing the Get-ESXCLI cmdlet with new -V2 parameter to perform two pings from an ESXi host:$esxcli2 = Get-ESXCLI -VMHost (Get-VMhost | Select -first 1) -V2

$arguments = $esxcli2.network.diag.ping.CreateArgs()$arguments.count = 2$arguments.host = “10.0.0.8”$esxcli2.network.diag.ping.Invoke($arguments)

Utilizing the Get-ESXCLI cmdlet with new -V2 parameter to perform two pings from an ESXi host:$esxcli2 = Get-ESXCLI -VMHost (Get-VMhost | Select -first 1) -V2

$arguments = $esxcli2.storage.vmfs.unmap.CreateArgs()$arguments.volumelabel = “Datastore1”$esxcli2.storage.vmfs.unmap.Invoke($arguments)

ESXCLI V2 Operations

Official PowerCLI Blog - http://blogs.vmware.com/PowerCLI/Documentation - http://vmware.com/support/developer/PowerCLI/index.htmlVMware PowerCLI Community - http://vmware.com/go/powercliTwitter - https://twitter.com/PowerCLILinkedIn - http://www.linkedin.com/groups/PowerCLI-Users-162324Facebook - https://www.facebook.com/vmwarepowercliVMware Education Course: Data Center Automation with vRealize Orchestrator and vSphere PowerCLI - https://mylearn.vmware.com/mgrreg/courses.cfm?a=one&id_subject=71972

Third-Party PowerCLI training from Pluralsight - http://www.pluralsight.com

PowerCLI Sites

To list all the snapshots for all virtual machines:Get-VM | Get-SnapshotTo snapshot a VM:New-Snapshot -VM "XP SP2" -Name

BeforePatch1To remove a snapshot:Remove-Snapshot -Snapshot $snapshot1 –RemoveChildren

Other cmdlets include:Set-Snapshot

Snapshot Operations

What is PowerCLI?

VMware vSphere PowerCLI is a powerful, easy-to-use scripting interface to manage the vSphere platform. Administrators canleverage more than 360 cmdletsto simplify everyday tasks.

PowerCLI Info

Learning PowerCLI

Managing VMware Infrastructure with Windows PowerShell TFM

PowerCLI Reference: Automating vSphere Administration

VMware vSphere PowerCLI Reference: Automating vSphere Administration, 2nd Edition

Mastering PowerCLI

PowerCLI Cookbook

PowerCLI Books PowerCLI Community

To list all virtual switches attached to a VM and some of their properties, use:Get-VirtualSwitch -VM (Get-VM -Name "Lync-Edge-03")To create a new virtual switch:New-VirtualSwitch -VMHost (Get-VMHost -Name 192.168.0.10) -Name Switch02To remove a virtual switch:$vs = Get-VirtualSwitch -VMHost 192.168.0.10 -Name VS23Remove-VirtualSwitch -VirtualSwitch $vsTo change the configuration of a virtual switch:$vs = New-VirtualSwitch -Host 192.168.0.10 -Name VirtSwitchSet-VirtualSwitch -VirtualSwitch $vs -MTU 500

Virtual Switch Operations

The following is a list of vApp cmdlets; use the Get-Help function for example uses:New-vApp -Name MyvApp -CpuLimitMhz 4000 -CpuReservationMhz 1000 -Location (Get-VMHost MyHost)

Other vApp cmdlets:Export-vApp Get-vApp Import-vApp Remove-vAppSet-vApp Start-vApp Stop-vApp

vApp Operations

Invoke-VMScript allows BIN, BASH, and Powershell Commands to be invoked remotelyInvoke-VMScript -VM LABTEST1 -ScriptText "dir" -GU Administrator -GP "VMware1!"

Invoke Commands in Virtual Machines

Using OVFConfiguration to deploy vApps:$ovfconfig = get-OvfConfiguration “myOvfTemplate.ovf”$ovfconfig.ToHashtable()

Use a hashtable:$ovfconfig = @{"vami.DNS.VMware_vCenter_Log_Insight" = "10.144.99.5";"vami.gateway.VMware_vCenter_Log_Insight" = "10.144.99.1";"vami.ip0.VMware_vCenter_Log_Insight" = "10.144.99.30";"vami.netmask0.VMware_vCenter_Log_Insight" = "255.255.255.0";"vm.rootpw" = "VMware1!";}

Or populate an object:$ovfconfig.NetworkMapping.Network.Value = “Network 1”$ovfconfig.vami.VM_1.ip0.Value = “10.144.99.30”$ovfPath = “c:\temp\myOvfTemplate.ovf”

Import-Vapp $ovfPath -OvfConfiguration $ovfConfig -VMHost $vmHost -Name “VM_OVF”

OVF Configuration

Files can be copied between user’s local machine and a VMCopy from a VM to the Local Machine:Copy-VMGuestFile -VM LABTEST1 -GuestUser Administrator -GuestPassword "VMware1!" -GuestToLocal -Source c:\temp\logfile.txt -Destination c:\temp\

Copy Files To/From VM

To list all resource pools on the connected VMware vSphere server and some oftheir properties: Get-ResourcePool

To create a new resource pool:$clusterRootRP = Get-ResourcePool -Location

(Get-Cluster ResearchAndDevelopmentCluster) -Name ResourcesNew-ResourcePool -Location $clusterRootRP -Name DevelopmentResources-CpuExpandableReservation $true -CpuReservationMhz

500 -CpuSharesLevel high -MemExpandableReservation $true-MemReservationMB 500 -MemSharesLevel high

Other resource pool cmdlets:Move-ResourcePoolRemove-ResourcePoolSet-ResourcePool

Resource Pool Operations

To list all tasks for a VMware vSphere server and some of their properties:Get-TaskTo stop a task (example: stops the task of removing the VM):Stop-Task -Task (Remove-VM -VM "Lync-Edge-03" -Confirm -

RunAsync)To wait until a task is completed before continuing:Wait-Task -Task (Remove-VM -VM "Lync-Edge-03" -Confirm -

RunAsync)

Task Information

Get-EsxTop –Counter

# View the fields available for vCPU counter:(Get-EsxTop –Counter –CounterName VCPU).FieldsGet-EsxTop –TopologyInfo

# View the entries of a specific topology:(Get-EsxTop –TopologyInfo –Topology SchedGroup).Entries | FT# Retrieve the counter values for “VCPU” and “SchedGroup" counters:Get-EsxTop –CounterName VCPU | FT * -AutoSizeGet-EsxTop –CounterName SchedGroup | FT * -AutoSize

ESXTOP through PowerCLI

To list all the port groups and some of their properties:$vs = Get-VirtualSwitch -VMHost 192.168.0.10 -Name Switch02Get-VirtualPortGroup -VirtualSwitch $vsTo add a new port group to a virtual switch:$vs = Get-VirtualSwitch -VMHost 192.168.0.10 -Name Switch02$vpg = New-VirtualPortGroup -VirtualSwitch $vs -Name VPG1Other cmdlets include:Remove-VirtualPortGroupSet-VirtualPortGroup

Port Group Operations

Get-AlarmDefinition # Returns all the defined alarms on the serversyou’re connected to.Get-AlarmDefinition -Name "virtual machine*" -Enabled $false# Returns all the disabled alarm definitions with names starting with“virtual machine.”Get-VMHost hostname | Get-AlarmDefinition # Returns all alarms thatapply to the host “hostname”. Includes alarms defined on this host andalarms inherited from the parent entity, or from any ancestors in theinventory hierarchy.Modify an alarm definition: Get-AlarmDefinition "Host memory status" |Set-AlarmDefinition -Name "Host memory" -Enabled $false# This will rename the alarm to “Host memory” and disable it.

Events and Alarms

Returns a VMware vSphere.Net view object by specified search criteria.$vm = Get-View -ViewType VirtualMachine -Filter @{"Name" = "MSWin XP SP2"}$hostView = Get-View -ID $vm.Runtime.Host$hostView.Summary.Runtime

Another example:(Get-View (Get-VMHost 'ESX1' | getview).ConfigManager.VmotionSystem).SelectVnc('vmk0')

API Reference: https://www.vmware.com/support/developer/vc-sdk/

API Operations

Create a tag category:New-TagCategory -Name "Owner" -Cardinality Single -EntityType

VirtualMachineRemove-TagCategory "Owner"Create a tag:$myTag = New-Tag -Name "jSmith" -Category "Owner"Assign a tag:Get-VM -Name "Lync-Edge-*" | New-TagAssignment -Tag $myTagGet-VM -Tag "jSmith"

Tag Operations

VMware vSphere PowerCLI frequently asked questions (FAQs) link:http://communities.vmware.com/docs/DOC-13700To find out what cmdlets are available: Get-VICommandTo show documentation for all available cmdlets: Get-PowerCLIDocumentationFor help with a cmdlet: Get-Help cmdlet-name –Full

Getting Started

To connect to a VMware vSphere server. Start a new session or reestablish aprevious session with a VMware vSphere server.$srv = Connect-VIServer –Server 192.168.0.10 -User Admin -Password Pass01To disconnect from the connected vSphere server:Disconnect-VIServer -Server $srv -Confirm:$false

How to Connect to vCenter Server or ESXi

Connect to vCenter Server firstConnect-SrmServer -SrmServerAddress 10.144.99.6 -User "administrator"-Password "myPassword"Disconnect-SrmServer -Server 10.144.99.6

How to Connect to SRM

Method to not have to input credentials every time you connect to vCenter:New-VICredentialStoreItem -Host vCSA.lab.local -User Root -Password "VMware1!"To remove credentials:Remove-VICredentialStoreItem -Host vCSA.lab.local -Confirm

How to Store vCenter Credentials

http://blogs.vmware.com/PowerCLI/Copyright © 2016 VMware, Inc. All rights reserved.

VMware vSphere PowerCLI 6.3 Release 1 Reference Poster