Connect-VIServer –Server "myvcenterserver" -Protocol https –User "myusername" –Password "mypassword"
Find the ESXi host version:
get-view -ViewType HostSystem -Property Name, Config.Product | select Name,{$_.Config.Product.FullName},{$_.Config.Product.Build} | ft -auto
get-view -ViewType HostSystem -Property Name, Config.Product | select Name,{$_.Config.Product.FullName},{$_.Config.Product.Build} | export-csv c:\Hostver.csv
Find ESXi Host Hardware:
Get-VMHost | Get-VMHostHardware -SkipAllSslCertificateChecks | Export-Csv c:\HostHardware.csv
Backup Host Configuration:
get-vmhost | get-vmhostfirmware -backupconfiguration -destinationpath "c:\temp"
How to find which VMs have Change Block Tracking (CBT) enabled:
Get-VM | Get-View | Sort Name | Select Name, @{N="ChangeTrackingStatus";E={$_.Config.ChangeTrackingEnabled}} > c:\cbt.txt
How to find if CBT is able on a VM:
(Get-VM -Name MyTestVM).ExtensionData.Config.ChangeTrackingEnabled
How to find which VMs have Change Block Tracking (CBT) disabled:
Get-VM | Where-Object{$_.ExtensionData.Config.ChangeTrackingEnabled -eq $false} > e:\cbt.txt
How to enable Change Block Tracking (CBT) on a VM:
$vmtest = Get-vm myvmname| get-view
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.changeTrackingEnabled = $true
$vmtest.reconfigVM($vmConfigSpec)
How to find if lockdown mode is enabled on a host:
Get-VMHost | Select Name, @{Name="LockdownModeEnabled";Expression={($_).Extensiondata.Config.adminDisabled}} | ft -auto
How to find VM snapshots:
Get-VM | Get-Snapshot | Select Created, VM
How to view ISCSI HBA status:
esxcli network ip connection list |grep 3260
Typically used with the following log:
tail -n 20 vmkwarning.log
Exporting vDS configurations:
Get-VDSwitch -Name my-vds-switch | Export-VDSwitch -Description "my-vds-switch" -Destination "c:\myvdsswitch.zip"
Get Events:
get-vievent -entity host/cluster/vm -start 01/01/2012 -finish 01/01/2016 > e:\MyEvents.txt
get-vievent -entity host/cluster/vm -start 01/01/2012 -finish 01/01/2016 | export-csv e:\MyEvents.csv
How to find the NTP servers of your hosts:
Get-VMHost |Sort Name|Select Name, @{N=“NTPServer“;E={$_ |Get-VMHostNtpServer}}, @{N=“ServiceRunning“;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd“}).Running}}
How to change the IP address within a VM OS (Requires VMware tools to be installed):
Get-VMGuestNetworkInterface MyVM -GuestCredential (get-credential) | Where-Object {$_.ip -ne $null} | Set-VMGuestNetworkInterface -ip "xxx.xxx.xxx.xxx" -netmask "255.255.255.0" -gateway "xxx.xxx.xxx.xxx" -guestcredential (get-credential)
How to find the number of VMs in a datastore:
Get-Datastore
| Select Name, @{N=
"NumVM"
;E={@(
$_
|
Get-VM
).Count}} | Sort Name
How to get VMFS version:
get-datastore | sort filesystemversion -descending |Format-table name, filesystemversion
How to Change the VM network:
get-datastore | sort filesystemversion -descending |Format-table name, filesystemversion
How to Change the VM network:
get-vm –name “MyVM” | get-networkadapter
| set-networkadapter –networkname “MyNetwork”
Changing VM memory and vCPU config (VM must be powered off):
get-vm –name “MyVM” | set-vm –memoryGb 2 -NumCpu 2
How to find VMs created in the last 14 days:
Get-VIEvent -maxsamples
1000000 -Start (Get-Date).AddDays(-14) | where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} |Sort CreatedTime -Descending |Select
CreatedTime, UserName,FullformattedMessage
How to Enable SSH on an ESXi host:
Get-VMHost myesxihost.mycompany.com | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Start-VMHostService
How to Disable SSH on an ESXi host:
Get-VMHost myesxihost.mycompany.com | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Stop-VMHostService
How to enable Lockdown mode
(get-vmhost myesxihost.mycompany.com | get-view).EnterLockdownMode() | get-vmhost | select Name,@{N="LockDown";E={$_.Extensiondata.Config.adminDisabled}} | ft -auto Name LockDown
How to disable Lockdown mode
(get-vmhost myesxihost.mycompany.com | get-view).ExitLockdownMode()
How to find the number of VMs in each datastore:
Get
-Datastore
|
Select
Name, @{N=
"NumVM"
;E={@($_ | Get
-VM
).Count}} |
Sort
Name
How to disconnect from the current VIServer:Disconnect-VIServer -Server MYVIServer
No comments:
Post a Comment