Difference between revisions of "PowerCLI"
From HackerNet
Helikopter (talk | contribs) |
Helikopter (talk | contribs) m (→Exempel) |
||
Line 12: | Line 12: | ||
Get-Datastore | Get-Datastore | ||
Get-VM -Datastore Datastore1 | Move-VM -Datastore Datastore2 -DiskStorageFormat thin | Get-VM -Datastore Datastore1 | Move-VM -Datastore Datastore2 -DiskStorageFormat thin | ||
+ | |||
+ | Flytta alla vms från en host till en annan. | ||
+ | Get-VMHost 172.20.0.2 | Get-VM | Move-VM -destination 172.20.0.8 | ||
Visa alla notes | Visa alla notes |
Revision as of 20:38, 25 June 2015
PowerCLI är ett Windows Powershell-gränssnitt för hantering av VMware vSphere. PowerCLI distribueras som en Powershell snapin, och innehåller över 370 Powershell-cmdlets för att hantera och automatisera vSphere och vCloud.
"a powerful command-line tool that lets you automate all aspects of vSphere management, including network, storage, VM, guest OS and more" - VMware
Installation
Ladda ner installationsfilen från VMwares hemsida. Anslut till din ESXi/vCenter med:
Connect-VIServer
Exempel
Flytta alla vms från en datastore till en annan.
Get-Datastore Get-VM -Datastore Datastore1 | Move-VM -Datastore Datastore2 -DiskStorageFormat thin
Flytta alla vms från en host till en annan.
Get-VMHost 172.20.0.2 | Get-VM | Move-VM -destination 172.20.0.8
Visa alla notes
Get-VM | Select-Object -ExpandProperty Notes
Script
Ett script för att skapa vm. New-VM.ps1
$VSPHERE = Read-host "Skriv IP/DNS-namn till vCenter/ESXi" Connect-VIServer $VSPHERE $VMName = Read-host "Enter the name of the VM you wish to create" Get-VMHost | Format-Wide $HOSTName = Read-host "Enter host" Get-Datastore | Format-Wide $DSName = Read-Host "Enter datastore" $VERSION = Read-Host "Enter VM-Version, exempel v9" $NUMCPU = Read-Host "Antal CPU-cores" $MEMORYMB = Read-Host "RAM, Antal MB" $DiskGB = Read-Host "Disk, Antal GB" Get-VirtualPortGroup -VMHost $HOSTName $NETWORK = Read-Host "Select Network" $NOTES = Read-Host "Notes" [System.Enum]::GetNames([VMware.Vim.VirtualMachineGuestOsIdentifier]) | Format-Wide $GUESTID = Read-Host "Select that guestid" Write-Host -ForegroundColor Green "Now the magic happens" Write-Host "Creating VM" New-VM -Name $VMName -VMHost $HOSTName -Datastore $DSName -DiskStorageFormat Thin -version $VERSION -GuestId $GUESTID -NumCpu $NUMCPU -MemoryMB $MEMORYMB -Notes $NOTES -DiskGB $DiskGB -NetworkName $NETWORK | out-null Write-Host -ForegroundColor Green "Convert to vmxnet3?" Get-VM $VMName | Get-NetworkAdapter | Set-NetworkAdapter -Type vmxnet3 | out-null Start-Sleep -Seconds 1; Write-Host "Starting the VM" Start-vm -VM $VMName -runAsync Start-Sleep -Seconds 1; Write-Host -ForegroundColor Green "Power On Complete"