Powercli: Difference between revisions

From Piszczynski
m (6 revisions imported)
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 20: Line 20:
===Create VMs===
===Create VMs===


Get guest ID from template to set when using New-VM:
Get Guest ID from all VMs currently in the vSphere:<syntaxhighlight lang="powershell">
*Get-Template -Name "name_of_your_template"
(get-vm | get-vmguest).GuestID | sort | unique
*$template.ExtensionData.Config.GuestId
</syntaxhighlight>Get guest ID from template to set when using New-VM:<syntaxhighlight lang="powershell" line="1">
Get-Template -Name "name_of_your_template"
$template.ExtensionData.Config.GuestId
</syntaxhighlight>
*


==VM Management==
==VM Management==
===Disk Management===
===Disk Management===


Add new Hard disk:
Add new Hard disk:<syntaxhighlight lang="powershell">
New-HardDisk -VM <name of vm> -CapacityGB 100
</syntaxhighlight>See: https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/new-harddisk/#CreateNew


*'''New-HardDisk -VM <name of vm> -CapacityGB 100'''
== Get Snapshots ==
Get all snapshots in vSphere environment with the following command:<syntaxhighlight lang="powershell">
Get-Snapshot * | Select-Object -Property VM, Name, SizeGB, Children | Sort-Object -Property sizeGB -Descending | ft -AutoSize
</syntaxhighlight>


See: https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/new-harddisk/#CreateNew
== Get VM information ==
Get vm creation date:<syntaxhighlight lang="powershell">
(get-vm -name "<vm name>").ExtensionData.config.createdate
</syntaxhighlight>

Latest revision as of 11:16, 24 May 2024

VMware Powercli

VMware PowerCLI Docs

Connect to environment

  • Connect-VIServer -Server vcenter01 -User admin -Password pass

or

  • Connect-VIServer -Server vcenter01

See https://blogs.vmware.com/PowerCLI/2013/03/back-to-basics-connecting-to-vcenter-or-a-vsphere-host.html

Disconnect from all servers:

  • Disconnect-Viserver -Server *


Create VMs

Get Guest ID from all VMs currently in the vSphere:

(get-vm | get-vmguest).GuestID | sort | unique

Get guest ID from template to set when using New-VM:

Get-Template -Name "name_of_your_template"
$template.ExtensionData.Config.GuestId

VM Management

Disk Management

Add new Hard disk:

New-HardDisk -VM <name of vm> -CapacityGB 100

See: https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/new-harddisk/#CreateNew

Get Snapshots

Get all snapshots in vSphere environment with the following command:

Get-Snapshot * | Select-Object -Property VM, Name, SizeGB, Children | Sort-Object -Property sizeGB -Descending | ft -AutoSize

Get VM information

Get vm creation date:

 (get-vm -name "<vm name>").ExtensionData.config.createdate