Powercli: Difference between revisions

From Piszczynski
piszczynski>Aleks
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:


== VMware Powercli ==
== VMware Powercli ==
[https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/ VMware PowerCLI Docs]


===Connect to environment===
===Connect to environment===
Line 14: Line 16:
Disconnect from all servers:
Disconnect from all servers:
*'''Disconnect-Viserver -Server *'''
*'''Disconnect-Viserver -Server *'''
===Create VMs===
Get Guest ID from all VMs currently in the vSphere:<syntaxhighlight lang="powershell">
(get-vm | get-vmguest).GuestID | sort | unique
</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