vmware vsphere powercli 6.3 release 1 reference poster · vmware vsphere powercli quick reference...

1
VMware vSphere PowerCLI Quick Reference Examples Get-ErrorReport Get-PowerCLIConfiguration Set-PowerCLIConfiguration Get-PowerCLIVersion PowerCLI Settings Get-AdvancedSetting New-AdvancedSetting Remove-AdvancedSetting Set-AdvancedSetting Get-AlarmAction New-AlarmAction Remove-AlarmAction Get-AlarmActionTrigger New-AlarmActionTrigger Remove-AlarmActionTrigger Get-AlarmDefinition Set-AlarmDefinition Get-Annotation Set-Annotation Get-ContentLibraryItem Get-CustomAttribute New-CustomAttribute Remove-CustomAttribute Set-CustomAttribute Get-Datastore Move-Datastore New-Datastore Remove-Datastore Set-Datastore Get-DatastoreCluster New-DatastoreCluster Remove-DatastoreCluster Set-DatastoreCluster Copy-DatastoreItem Get-DrsRecommendation Invoke-DrsRecommendation Get-DrsRule New-DrsRule Remove-DrsRule Set-DrsRule Get-EsxCli Get-EsxTop Get-Folder Move-Folder New-Folder Remove-Folder Set-Folder Get-Inventory Move-Inventory Remove-Inventory Get-OvfConfiguration Get-Task Stop-Task Wait-Task Get-VIAccount Get-View Get-VIObjectByVIView Get-VIPermission New-VIPermission Remove-VIPermission Set-VIPermission Get-VIPrivilege Get-VIProperty New-VIProperty Remove-VIProperty Get-VIRole New-VIRole Remove-VIRole Set-VIRole Connect-VIServer Disconnect-VIServer VMware vSphere Server Set-Datacenter Get-Datacenter Move-Datacenter New-Datacenter Remove-Datacenter Datacenter Operations Get-Cluster Move-Cluster New-Cluster Remove-Cluster Set-Cluster Get-DrmInfo Cluster Operations Dismount-Tools Mount-Tools Update-Tools Wait-Tools Get-VMGuest Restart-VMGuest Stop-VMGuest Suspend-VMGuest Copy-VMGuestFile Get-VMGuestNetworkInterface Set-VMGuestNetworkInterface Get-VMGuestRoute New-VMGuestRoute Remove-VMGuestRoute Invoke-VMScript Guest OS Switch-ActiveDeployRuleSet Repair-DeployImageCache Add-DeployRule Copy-DeployRule Get-DeployRule New-DeployRule Remove-DeployRule Set-DeployRule Get-DeployRuleSet Set-DeployRuleSet Repair-DeployRuleSetCompliance Test-DeployRuleSetCompliance Get-VMHostImageProfile Get-VMHostMatchingRules Auto Deploy Operations Attach-Baseline Detach-Baseline Get-Baseline Remove-Baseline Get-Compliance Test-Compliance Update-Entity Add-EntityBaseline Remove-EntityBaseline Copy-Patch Download-Patch Get-Patch Stage-Patch Sync-Patch Get-PatchBaseline New-PatchBaseline Set-PatchBaseline Scan-Inventory Remediate-Inventory vCenter Update Manager Get-OMAlert Set-OMAlert Get-OMAlertDefinition Get-OMAlertSubType Get-OMAlertType Get-OMRecommendation Get-OMResource Connect-OMServer Disconnect-OMServer Get-OMStat Get-OMStatKey Get-OMUser vRealize Operations Apply-ESXImageProfile Compare-EsxImageProfile Export-EsxImageProfile Get-EsxImageProfile New-EsxImageProfile Set-EsxImageProfile Remove-EsxImageProfile Add-EsxSoftwareDepot Get-EsxSoftwareDepot Remove-EsxSoftwareDepot Add-EsxSoftwarePackage Get-EsxSoftwarePackage Remove-EsxSoftwarePackage Image Builder Operations Export-VMHostProfile Get-VMHostProfile Import-VMHostProfile Invoke-VMHostProfile New-VMHostProfile Remove-VMHostProfile Set-VMHostProfile Test-VMHostProfileCompliance Get-VMHostProfileRequiredInput Host Profiles Get-IScsiHbaTarget New-IScsiHbaTarget Remove-IScsiHbaTarget Set-IScsiHbaTarget Get-NfsUser New-NfsUser Remove-NfsUser Set-NfsUser Get-ScsiController New-ScsiController Set-ScsiController Get-ScsiLun Set-ScsiLun Get-ScsiLunPath Set-ScsiLunPath Get-SpbmCapability Get-SpbmCompatibleStorage Get-SpbmEntityConfiguration Set-SpbmEntityConfiguration New-SpbmRule New-SpbmRuleSet Export-SpbmStoragePolicy Get-SpbmStoragePolicy Import-SpbmStoragePolicy New-SpbmStoragePolicy Remove-SpbmStoragePolicy Set-SpbmStoragePolicy Get-VAIOFilter New-VAIOFilter Remove-VAIOFilter Set-VAIOFilter Get-VasaProvider New-VasaProvider Remove-VasaProvider Get-VasaStorageArray Storage Operations Get-ResourcePool Move-ResourcePool New-ResourcePool Remove-ResourcePool Set-ResourcePool Resource Pool Operations Connect-SrmServer Disconnect-SrmServer Site Recovery Manager Get-VsanDisk New-VsanDisk Remove-VsanDisk Get-VsanDiskGroup New-VsanDiskGroup Remove-VsanDiskGroup VSAN Operations Get-OVFConfiguration OVF Configuration Get-MirageAppLayer Get-MirageAssignment Invoke-MirageAssignment Get-MirageBaseLayer Dismount-MirageCvd Get-MirageCvd New-MirageCvd Remove-MirageCvd Reset-MirageCvd Restart-MirageCvd Set-MirageCvd Sync-MirageCvd Set-MirageCvdAppLayer Get-MirageCvdCollection Get-MirageOsMigration Invoke-MirageOsMigration New-MirageOsMigration Get-MiragePendingDevice Get-MiragePolicy Connect-MirageServer Disconnect-MirageServer Get-MirageVolume Mirage Operations Get-Tag New-Tag Remove-Tag Set-Tag Get-TagAssignment New-TagAssignment Remove-TagAssignment Get-TagCategory New-TagCategory Remove-TagCategory Set-TagCategory Tags Get-Log Get-LogType Get-OSCustomizationNicMapping New-OSCustomizationNicMapping Remove-OSCustomizationNicMapping Set-OSCustomizationNicMapping Get-OSCustomizationSpec New-OSCustomizationSpec Remove-OSCustomizationSpec Set-OSCustomizationSpec Get-Stat Get-StatInterval New-StatInterval Remove-StatInterval Set-StatInterval Get-StatType Get-VICredentialStoreItem New-VICredentialStoreItem Remove-VICredentialStoreItem Get-VIEvent Logs/Reporting/Configuration Get-CDDrive New-CDDrive Remove-CDDrive Set-CDDrive Get-FloppyDrive New-FloppyDrive Remove-FloppyDrive Set-FloppyDrive Copy-HardDisk Get-HardDisk Move-HardDisk New-HardDisk Remove-HardDisk Set-HardDisk Get-NetworkAdapter New-NetworkAdapter Remove-NetworkAdapter Set-NetworkAdapter Add-PassthroughDevice Get-PassthroughDevice Remove-PassthroughDevice Get-Snapshot New-Snapshot Remove-Snapshot Set-Snapshot Get-Template Move-Template New-Template Remove-Template Set-Template Get-UsbDevice Remove-UsbDevice Get-VM Move-VM New-VM Remove-VM Restart-VM Set-VM Start-VM Stop-VM Suspend-VM Open-VMConsoleWindow Get-VMQuestion Set-VMQuestion Get-VMResourceConfiguration Set-VMResourceConfiguration Virtual Machine Operations Export-VApp Get-VApp Import-VApp Move-VApp New-VApp Remove-VApp Set-VApp Start-VApp Stop-VApp vApps Get-HAPrimaryVMHost Add-VMHost Get-VMHost Move-VMHost Remove-VMHost Restart-VMHost Set-VMHost Start-VMHost Stop-VMHost Suspend-VMHost Get-VMHostAccount New-VMHostAccount Remove-VMHostAccount Set-VMHostAccount Get-VMHostAdvancedConfiguration Set-VMHostAdvancedConfiguration Get-VMHostAttributes Get-VMHostAuthentication Set-VMHostAuthentication Get-VMHostAvailableTimeZone Get-VMHostDiagnosticPartition Set-VMHostDiagnosticPartition Get-VMHostDisk Format-VMHostDiskPartition Get-VMHostDiskPartition Get-VMHostFirewallDefaultPolicy Set-VMHostFirewallDefaultPolicy Get-VMHostFirewallException Set-VMHostFirewallException Get-VMHostFirmware Set-VMHostFirmware Get-VMHostHardware Get-VMHostHba Set-VMHostHba Get-VMHostModule Set-VMHostModule Get-VMHostNetwork Set-VMHostNetwork Get-VMHostNetworkAdapter New-VMHostNetworkAdapter Remove-VMHostNetworkAdapter Set-VMHostNetworkAdapter Add-VMHostNtpServer Get-VMHostNtpServer Remove-VMHostNtpServer Get-VMHostPatch Install-VMHostPatch Get-VMHostPciDevice Get-VMHostRoute New-VMHostRoute Remove-VMHostRoute Set-VMHostRoute Get-VMHostService Restart-VMHostService Set-VMHostService Start-VMHostService Stop-VMHostService Get-VMHostSnmp Set-VMHostSnmp Test-VMHostSnmp Get-VMHostStartPolicy Set-VMHostStartPolicy Get-VMHostStorage Set-VMHostStorage Get-VMHostSysLogServer Set-VMHostSysLogServer Get-VMStartPolicy Set-VMStartPolicy ESXi Host Operations Get-NicTeamingPolicy Set-NicTeamingPolicy Get-SecurityPolicy Set-SecurityPolicy Get-VDBlockedPolicy Set-VDBlockedPolicy Get-VDPort Set-VDPort Export-VDPortGroup Get-VDPortgroup New-VDPortgroup Remove-VDPortGroup Set-VDPortgroup Get-VDPortgroupOverridePolicy Set-VDPortgroupOverridePolicy Get-VDSecurityPolicy Set-VDSecurityPolicy Export-VDSwitch Get-VDSwitch New-VDSwitch Remove-VDSwitch Set-VDSwitch Add-VDSwitchPhysicalNetworkAdapter Remove-VDSwitchPhysicalNetworkAdapter Get-VDSwitchPrivateVlan New-VDSwitchPrivateVlan Remove-VDSwitchPrivateVlan Add-VDSwitchVMHost Remove-VDSwitchVMHost Get-VDTrafficShapingPolicy Set-VDTrafficShapingPolicy Get-VDUplinkLacpPolicy Set-VDUplinkLacpPolicy Get-VDUplinkTeamingPolicy Set-VDUplinkTeamingPolicy Set-VDVlanConfiguration Get-VirtualPortGroup New-VirtualPortGroup Remove-VirtualPortGroup Set-VirtualPortGroup Get-VirtualSwitch New-VirtualSwitch Remove-VirtualSwitch Set-VirtualSwitch Add-VirtualSwitchPhysicalNetworkAdapter Remove-VirtualSwitchPhysicalNetworkAdapter Network Operations Add-AutomaticPool Update-AutomaticPool Add-AutomaticLinkedClonePool Update-AutomaticLinkedClonePool Get-ComposerDomain Get-ConnectionBroker Update-ConnectionBroker Get-DesktopPhysicalMachine Get-DesktopVM Get-EventReport Get-EventReportList Get-GlobalSetting Update-GlobalSetting Get-License Set-License Send-LinkedCloneRebalance Send-LinkedCloneRecompose Send-LinkedCloneRefresh Get-LocalSession Send-LocalSessionRollback Add-ManualPool Update-ManualPool Add-ManualUnmanagedPool Update-ManualUnmanagedPool Get-Monitor Get-Pool Remove-Pool Add-PoolEntitlement Get-PoolEntitlement Remove-PoolEntitlement Get-ProfileDisk Get-TerminalServer Add-TerminalServerPool Update-TerminalServerPool Get-RemoteSession Send-SessionDisconnect Send-SessionLogoff Get-User Remove-UserOwnership Update-UserOwnership Add-ViewVC Get-ViewVC Remove-ViewVC Update-ViewVC Send-VMReset PowerShell for View Operations Get-Catalog Get-CIAccessControlRule New-CIAccessControlRule Remove-CIAccessControlRule Set-CIAccessControlRule Add-CIDatastore Get-CIDatastore Get-CINetworkAdapter Set-CINetworkAdapter Get-CIRole Connect-CIServer Connect-CisServer Disconnect-CIServer Disconnect-CisServer Get-CisService Get-CIUser Get-CIVApp Import-CIVApp New-CIVApp Remove-CIVApp Restart-CIVApp Set-CIVApp Start-CIVApp Stop-CIVApp Suspend-CIVApp Restart-CIVAppGuest Stop-CIVAppGuest Suspend-CIVAppGuest Get-CIVAppNetwork New-CIVAppNetwork Remove-CIVAppNetwork Set-CIVAppNetwork Get-CIVAppStartRule Set-CIVAppStartRule Get-CIVAppTemplate Import-CIVAppTemplate New-CIVAppTemplate Remove-CIVAppTemplate Set-CIVAppTemplate Get-CIView Get-CIVM New-CIVM Restart-CIVM Start-CIVM Stop-CIVM Suspend-CIVM Restart-CIVMGuest Stop-CIVMGuest Get-CIVMTemplate Search-Cloud Get-CloudCommand Get-ExternalNetwork Get-Media Get-NetworkPool Get-Org New-Org Remove-Org Set-Org Get-OrgNetwork New-OrgNetwork Remove-OrgNetwork Set-OrgNetwork Get-OrgVdc New-OrgVdc Remove-OrgVdc Set-OrgVdc Get-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 of VM";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-Object VMware.Vim.LatencySensitivity $spec.LatencySensitivity.Level = [VMware.Vim.LatencySensitivitySensitivityLevel]::high $vm.ExtensionData.reReconfigVM($spec) Quick Helpful Commands For a list of datastores and other properties: Get-Datastore Other datastore cmdlets include: New-Datastore Remove-Datastore Datastore Operations The following is a list of all folder- related cmdlets: Get-Folder Move-Folder New-Folder Remove-Folder Set-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 $vmhost Get-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 1 Remove-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.html VMware PowerCLI Community - http://vmware.com/go/powercli Twitter - https://twitter.com/PowerCLI LinkedIn - http://www.linkedin.com/groups/PowerCLI-Users-162324 Facebook - https://www.facebook.com/vmwarepowercli VMware 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-Snapshot To snapshot a VM: New-Snapshot -VM "XP SP2" -Name BeforePatch1 To 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 can leverage more than 360 cmdlets to 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 Switch02 To remove a virtual switch: $vs = Get-VirtualSwitch -VMHost 192.168.0.10 -Name VS23 Remove-VirtualSwitch -VirtualSwitch $vs To change the configuration of a virtual switch: $vs = New-VirtualSwitch -Host 192.168.0.10 -Name VirtSwitch Set-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-vApp Set-vApp Start-vApp Stop-vApp vApp Operations Invoke-VMScript allows BIN, BASH, and Powershell Commands to be invoked remotely Invoke-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.ovfImport-Vapp $ovfPath -OvfConfiguration $ovfConfig -VMHost $vmHost -Name VM_OVFOVF Configuration Files can be copied between user’s local machine and a VM Copy 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 of their properties: Get-ResourcePool To create a new resource pool: $clusterRootRP = Get-ResourcePool -Location (Get-Cluster ResearchAndDevelopmentCluster) -Name Resources New-ResourcePool -Location $clusterRootRP -Name DevelopmentResources -CpuExpandableReservation $true -CpuReservationMhz 500 -CpuSharesLevel high -MemExpandableReservation $true -MemReservationMB 500 -MemSharesLevel high Other resource pool cmdlets: Move-ResourcePool Remove-ResourcePool Set-ResourcePool Resource Pool Operations To list all tasks for a VMware vSphere server and some of their properties: Get-Task To 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).Fields Get-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 * -AutoSize Get-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 Switch02 Get-VirtualPortGroup -VirtualSwitch $vs To 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 VPG1 Other cmdlets include: Remove-VirtualPortGroup Set-VirtualPortGroup Port Group Operations Get-AlarmDefinition # Returns all the defined alarms on the servers you’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 that apply to the host “hostname”. Includes alarms defined on this host and alarms inherited from the parent entity, or from any ancestors in the inventory 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" = "MS Win 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 VirtualMachine Remove-TagCategory "Owner" Create a tag: $myTag = New-Tag -Name "jSmith" -Category "Owner" Assign a tag: Get-VM -Name "Lync-Edge-*" | New-TagAssignment -Tag $myTag Get-VM -Tag "jSmith" Tag Operations VMware vSphere PowerCLI frequently asked questions (FAQs) link: http://communities.vmware.com/docs/DOC-13700 To find out what cmdlets are available: Get-VICommand To show documentation for all available cmdlets: Get-PowerCLIDocumentation For help with a cmdlet: Get-Help cmdlet-name –Full Getting Started To connect to a VMware vSphere server. Start a new session or reestablish a previous session with a VMware vSphere server. $srv = Connect-VIServer –Server 192.168.0.10 -User Admin -Password Pass01 To disconnect from the connected vSphere server: Disconnect-VIServer -Server $srv -Confirm:$false How to Connect to vCenter Server or ESXi Connect to vCenter Server first Connect-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

Upload: donga

Post on 25-May-2018

280 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: VMware vSphere PowerCLI 6.3 Release 1 Reference Poster · VMware vSphere PowerCLI Quick Reference Examples ... Mastering PowerCLI ... VMware vSphere PowerCLI 6.3 Release 1 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