Get VM list from a datstore
Get-datastore | Where {$_.name -like ‘*DATASTORE01*’} | Get-VM
Find snapshots
Get-Snapshot -vm * -name “VEEAM BACKUP*” | Format-Table -property VM,Name
Clear snapshots
Get-Snapshot -vm * -name “VEEAM BACKUP*” | remove-snapshot
List VM and What Datastore
get-vmhost |get-datastore|%{$ds=$_; $ds.Extensiondata.Vm|%{$_|select @{n=’vm name’;e={(Get-View -property name -Id $_.toString()).name}},@{n=’ds name’;e={$ds.name}} }}
List vm in what dr group and what storage
cretae ps1 file with this:
$clusterName = ‘Cluster’
$cluster = Get-Cluster -Name $clusterName
$vmTab = @{}
Get-VM -Location $cluster | %{
$vmTab.Add($_.Name,@{
Name = $_.Name
VMGroup = @()
Rule = @()
})
}
foreach($group in (Get-DrsVMGroup -Cluster $cluster)){
$group.VM | %{
$vmTab[$_].VMGroup += $group.Name
}
}
foreach($rule in (Get-DrsVMToVMRule -Cluster $cluster)){
$rule.VM | %{
$vmTab[$_].Rule += $rule.Name
}
}
$vmTab.GetEnumerator() |
Select -ExpandProperty Value |
Select @{N=’Name’;E={$_[‘Name’]}},
@{N=’Rule’;E={$_[‘Rule’] -join ‘|’}},
@{N=’Group’;E={$_[‘VMGroup’] -join ‘|’}}
HandsOnLab HOL-1911-05-SDC-HOL
Connect-VIServer vcsa-01a.corp.local -User administrator@corp.local -Password VMware1!
Get-Datacenter
$folder = Get-Folder -NoRecursion | New-Folder -Name HOL -Verbose
$folder = Get-Folder -NoRecursion
New-Datacenter -Location $folder -Name HOL_DC -Verbose
Get-Datacenter
Linux:
pwsh
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Connect-VIServer 192.168.210.22 -User administrator@corp.local -Password VMware1!
$folder = Get-Folder -NoRecursion | New-Folder -Name HOL -Verbose
New-Datacenter -Location $folder -Name HOL-DC -Verbose
Get-Datacenter
Windows:
Get-cluster
New-Cluster -Location RegionA01 -Name MyCluster -HAEnabled -DRSEnabled
Get-Cluster -Name MyCluster
Remove-Cluster -Cluster MyCluster -Confirm:$false -Verbose
Get-Cluster
Set-Cluster -Cluster RegionA01-COMP01 -HAEnabled:$true -Confirm:$false
Set-Cluster -Cluster RegionA01-COMP01 -HARestartPriority Low -Confirm:$false -Verbose
Set-Cluster -Cluster RegionA01-COMP01 -DrsAutomationLevel FullyAutomated -Confirm:$false
Set-Cluster -Cluster RegionA01-COMP01 -DrsEnabled:$false -Confirm:$false
Get-ResourcePool -Name Resources -Location RegionA01-COMP01
$myClusterRootRP = Get-Cluster RegionA01-COMP01 | Get-ResourcePool -Name Resources
New-ResourcePool -Name Production -Location $myClusterRootRP -CPUSharesLevel High -MemSharesLevel High
Move-VM app-01a –Destination Production
Set-ResourcePool -ResourcePool Production -CpuSharesLevel Normal
Get-Folder
New-Folder -Name Infrastructure -Location (Get-Datacenter -Name RegionA01 | Get-Folder -Name VM)
Get-Folder -Name Infrastructure | New-Folder -Name “Domain Controllers”
Move-VM -VM app-01a -InventoryLocation Infrastructure
Get-Folder -NoRecursion | New-Folder -Name MyDatacenter
Move-Datacenter -Datacenter RegionA01 -Destination MyDatacenter
New-Folder -Name InfrastructureDS -Location (Get-Datacenter -Name RegionA01 | Get-Folder -Name datastore)
Move-Datastore -Datastore RegionA01-ISCSI01-COMP01 -Destination InfrastructureDS
New-Folder -Name InfrastructureH -Location (Get-Datacenter -Name RegionA01 | Get-Folder -Name host)
Move-Cluster -Cluster RegionA01-COMP01 -Destination InfrastructureH
Linux:
Get-VMHost
Get-VMHost -Location RegionB01
Get-VMHost -VM app-01b
Add-VMHost -Name esx-03b.corp.local -Location RegionB01-COMP01 -User root -Password VMware1! -Force
Set-VMHost -VMHost esx-03b.corp.local -State Maintenance -RunAsync
Get-VMHost
Set-VMHost -VMHost esx-03b.corp.local -State Connected
Get-VMhost
Get-Datastore
Get-Datastore -Name RegionB01-ISCSI01-COMP01
Get-VMHostStorage -VMHost esx-01b.corp.local -RescanAllHba
Get-VMHostStorage -VMHost esx-01b.corp.local -RescanVmfs
Windows:
Connect-VIServer vcsa-01a.corp.local -User administrator@corp.local -Password VMware1!
Get-VM
Set-VM -VM template-01a -ToTemplate -Confirm:$false
New-VM -Template template-01a -Name HOL-VM1 -VMHost esx-01a.corp.local -DiskStorageFormat Thin
Set-VM HOL-VM1 -NumCpu 4 -MemoryGB 8
Set-Cluster -Cluster RegionA01-COMP01 -HAEnabled:$true
Set-VM HOL-VM1 -HARestartPriority High
Get-HardDisk HOL-VM1
Get-HardDisk HOL-VM1 | Set-HardDisk -CapacityGB 10
Restart-VMGuest app-01a -Confirm:$false
Stop-VMGuest kms-01a -Confirm:$false
Stop-VM app-01a -Confirm:$false
Get-VM
Start-VM app-01a
New-Snapshot -VM app-01a.corp.local -Name “app-01a basic” -Description “This is a basic snapshot”
Get-Snapshot app-01a
Get-Snapshot app-01a -Name “app-01a basic” | Remove-Snapshot
Get-Snapshot app-01a
Leave a Reply