domingo, 30 de marzo de 2014

PowerShell para novatos III, Hyper-V Powershell

Bueno, parece ser que el Power Shell es de gran utilidad y uso en la gestión de Hyper-V.
He decidio crear esta entrada para mostrar algunas líneas que pueden ser útiles y en un momento dado pueden sacar de un entuerto ;-)

Para sacar todos los comandos que tiene Hyper-V:

Get-Command -Module Hyper-v

Una vez que vemos todos los comandos, podremos sacar información de uno que nos interese con, en nuestro caso "save-VM" (puede que se tenga que conectar para descargar la última versión):

Get-help save-VM

NOMBRE
    Save-VM

SINOPSIS
    Saves a virtual machine.


SINTAXIS
    Save-VM [-Name] <String[]> [-AsJob] [-ComputerName <String[]>] [<CommonParameters>]


    Save-VM [-VM] <VirtualMachine[]> [-AsJob] [<CommonParameters>]

DESCRIPCIÓN
    The Save-VM cmdlet saves a virtual machine. This is similar to hibernating a physical machine.


VÍNCULOS RELACIONADOS
    Online Version:
http://go.microsoft.com/fwlink/?LinkID=306936
NOTAS
    Para ver los ejemplos, escriba: "get-help Save-VM -examples".
    Para obtener más información, escriba: "get-help Save-VM -detailed".
    Para obtener información técnica, escriba: "get-help Save-VM -full".
    Para obtener ayuda disponible en línea, escriba: "get-help Save-VM -online"


Supongamos ahora que buscamos un comando del cual no sabemos nada... solo sabemos que es "part" o algo asi. En ese caso lanzaremos el siguiente comando:

PS C:\WINDOWS\system32> Get-Command *part*

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Function        Add-PartitionAccessPath                            Storage
Function        Get-NetCompartment                                 NetTCPIP
Function        Get-Partition                                      Storage
Function        Get-PartitionSupportedSize                         Storage
Function        New-Partition                                      Storage
Function        Remove-Partition                                   Storage
Function        Remove-PartitionAccessPath                         Storage
Function        Resize-Partition                                   Storage
Function        Set-Partition                                      Storage
Application     diskpart.exe


Para ver las características de varios host pondremos

Get-VMHost -ServerName host1,host2,

Name     LogicalProcessorCount MemoryCapacity(M) VirtualMachineMigrationEnabled
----     --------------------- ----------------- ------------------------------
host1 4                     8173,27734375     False

host2 4                     8173,27734375     True


Listado de las maquinas virtuales en sistema:

PS C:\WINDOWS\system32> Get-VM

Name      State CPUUsage(%) MemoryAssigned(M) Uptime   Status
----      ----- ----------- ----------------- ------   ------
HV-Ubuntu Off   0           0                 00:00:00 Funcionamiento normal
TestVM    Off   0           0                 00:00:00 Funcionamiento normal

Para sacar solo los datos que nos interesan, por ejemplo nombre y status:

PS C:\WINDOWS\system32> Get-VM |Format-List name,status

Name   : HV-Ubuntu
Status : Funcionamiento normal
Name   : TestVM
Status : Funcionamiento normal

Sacar información de los Switch de red en sistema


PS C:\WINDOWS\system32> Get-VMSwitch
Name             SwitchType NetAdapterInterfaceDescription
----             ---------- ------------------------------
Red Externa Wifi External   Qualcomm Atheros AR9285 Wireless Network Adapter
Red Interna      Private

Pero si queremos mas detalle del Switch como sus características completas usaremos -VMname para referirnos a el y format list * que nos mostrará todo.

Get-VmSwitch -VMName "MyVMswitch" | format-list *

Para ver el pool de recursos del servidor lanzaremos el siguiente comando (primordial hace referencia los mínimos montados por el sistema):

PS C:\WINDOWS\system32> Get-VMResourcePool

Name       ResourcePoolType       ParentName ResourceMeteringEnabled
----       ----------------       ---------- -----------------------
Primordial Processor                         False
Primordial FibreChannelConnection            False
Primordial FibreChannelPort                  False
Primordial VFD                               False
Primordial ISO                               False
Primordial VHD                               False
Primordial Ethernet                          False
Primordial Memory                            False


Crear disco virtual:

New-VHD -Path \\CAFSC01\HVCVMStorage\HAVM01.VHDX -Dynamic -Size 127GB

Crear maquina virtual

New-VM -Name HAVM01 -Path \\CAFSC01\HVCVMStorage -Memory 1GB -SwitchName
"KEMLABNET01" -BootDevice CD -VHDPath \\CAFSC01\HVCVMStorage\HAVM01.VHDX


Añadir disco a a maquina virtual:

 Add-VMDvdDrive -VMName HAVM01 -Path \\CAFSC01\ISO\WS2012RTM.ISO

 No establecer autostartup

Set-VM -Name HAVM01 -AutomaticStartAction Nothing


No hay comentarios:

Publicar un comentario