• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell (nivel medio)
  • Libro de PowerShell (nivel avanzado)
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

6. Virtualización en PowerShell (nivel intermedio)

Contenidos

  • Máquinas virtuales
    • Listar hosts virtuales
        • Ejemplo
          • Buscar la máquina virtual VM
    • Ver propiedades del host virtual
        • Ejemplo
          • Seleccionar la propiedad nombre de la máquina y nombre del interfaz de red
    • Crear host virtual
        • Ejemplo
          • Crear una máquina virtual con la memoria virtual 512MB, disco duro de 2GB
    • Actualizar propiedades de la máquina virtual
        • Ejemplos
          • Cambiar el número de procesadores de la máquina virtual
          • Usar memoria dinámica en la máquina virtual
    • Arrancar máquinas virtuales
        • Ejemplo
          • Arrancar una máquina virtual
    • Parar máquinas virtuales
        • Ejemplo
          • Parar una máquina virtual
    • Crear una instantánea
        • Ejemplo
          • Crear una instantánea en la máquina virtual
    • Ver las instantáneas de una máquina virtual
        • Ejemplo
          • Ver las instantáneas de una máquina virtual
    • Eliminar una máquina virtual
        • Ejemplo
          • Eliminar una máquina virtual
    • Gestión de discos virtuales
        • Ejemplos
          • Crear un disco virtual de tamaño dinámico
          • Crear un disco virtual de tamaño fijo
    • Añadir un disco virtual a una máquina virtual
        • Ejemplo
          • Añadir un disco virtual a una máquina virtual
    • Gestión de red virtual
        • Ejemplo
          • Crear un switch virtual
    • Ver información sobre la red virtual
        • Ejemplo
          • Ver información sobre la red virtual

La virtualización es un conjunto de técnicas hardware y/o software que permiten abstraer hardware y/o software creando la ilusión de que se están manejando dispositivos físicos, sistemas operativos, sesiones remotas de forma transparente al usuario.

Uno de los elementos principales de la virtualización es la máquina virtual que se está formada por recursos virtuales como una BIOS, memoria, procesador, disco duro, etc., y que se utilizan como si se tratase de recursos físicos.

Máquinas virtuales

Una máquina virtual está formada por una BIOS y un conjunto de recursos hardware (memoria, procesador, disco duro virtual, etc.) que se utilizan como si fuera la maquina física. Dentro de una maquina virtual se puede instalar cualquier sistema operativo, siempre y cuando el programa para virtualizar soporte ese sistema operativo. Desde las máquinas virtuales se puede imprimir, usar los dispositivos USB, navegar por la red, etc.

Microsoft dispone de herramientas para gestionar máquinas virtuales, una de ellas es Hyper-V.

Cmdlets sobre Hyper-V

PowerShell
1
Get-Command -Module Hyper-V

Listar hosts virtuales

Cmdlet

PowerShell
1
Get-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Name                {VMName}
CimSession          {}      
ComputerName        {}      
Credential          {}      
Id                  {}      
ClusterObject       {}      
Verbose             {vb}    
Debug               {db}    
ErrorAction         {ea}    
WarningAction       {wa}    
InformationAction   {infa}  
ErrorVariable       {ev}    
WarningVariable     {wv}    
InformationVariable {iv}    
OutVariable         {ov}    
OutBuffer           {ob}    
PipelineVariable    {pv}

Para listar un host en concreto

PowerShell
1
Get-VM -Name


Ejemplo
Buscar la máquina virtual VM

PowerShell
1
Get-VM -Name "VM" | Format-List *


Ver propiedades del host virtual

PowerShell
1
Get-VM | select *


Ejemplo
Seleccionar la propiedad nombre de la máquina y nombre del interfaz de red

PowerShell
1
Get-VM | select -ExpandProperty NetworkAdapters | Select-Object VMName,Name


Crear host virtual

Cmdlet

PowerShell
1
New-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Name                {VMName}
MemoryStartupBytes  {}      
BootDevice          {}      
NoVHD               {}      
SwitchName          {}      
NewVHDPath          {}      
NewVHDSizeBytes     {}      
VHDPath             {}      
Path                {}      
Version             {}      
Prerelease          {}      
Experimental        {}      
Generation          {}      
Force               {}      
AsJob               {}      
CimSession          {}      
ComputerName        {}      
Credential          {}      
Verbose             {vb}    
Debug               {db}    
ErrorAction         {ea}    
WarningAction       {wa}    
InformationAction   {infa}  
ErrorVariable       {ev}    
WarningVariable     {wv}    
InformationVariable {iv}    
OutVariable         {ov}    
OutBuffer           {ob}    
PipelineVariable    {pv}    
WhatIf              {wi}    
Confirm             {cf}


Ejemplo
Crear una máquina virtual con la memoria virtual 512MB, disco duro de 2GB

PowerShell
1
New-VM -Name "MyNewVM" -MemoryStartupBytes 512MB -NewVHDPath "D:\MyNewVM.vhdx" -NewVHDSizeBytes 2GB

Actualizar propiedades de la máquina virtual

Cmdlets

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Set-VM
Set-VMBios
Set-VMComPort
Set-VMDvdDrive
Set-VMFibreChannelHba
Set-VMFirmware
Set-VMFloppyDiskDrive
Set-VMGpuPartitionAdapter
Set-VMHardDiskDrive
Set-VMHost
Set-VMHostCluster
Set-VMKeyProtector
Set-VMKeyStorageDrive
Set-VMMemory
Set-VMMigrationNetwork
Set-VMNetworkAdapter
Set-VMNetworkAdapterFailoverConfiguration
Set-VMNetworkAdapterIsolation
Set-VMNetworkAdapterRdma
Set-VMNetworkAdapterRoutingDomainMapping
Set-VMNetworkAdapterTeamMapping
Set-VMNetworkAdapterVlan
Set-VMPartitionableGpu
Set-VMProcessor
Set-VMRemoteFx3dVideoAdapter
Set-VMReplication
Set-VMReplicationAuthorizationEntry
Set-VMReplicationServer
Set-VMResourcePool
Set-VMSan
Set-VMSecurity
Set-VMSecurityPolicy
Set-VMSwitch
Set-VMSwitchExtensionPortFeature
Set-VMSwitchExtensionSwitchFeature
Set-VMSwitchTeam
Set-VMVideo


Ejemplos
Cambiar el número de procesadores de la máquina virtual

PowerShell
1
Set-VMProcessor "MyNewVM" -Count 2

Usar memoria dinámica en la máquina virtual

PowerShell
1
Set-VMMemory "MyNewVM" -DynamicMemoryEnabled $true


Arrancar máquinas virtuales

Cmdlet

PowerShell
1
Start-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CimSession          {}      
ComputerName        {}      
Credential          {}      
VM                  {}      
Name                {VMName}
AsJob               {}      
Passthru            {}      
Verbose             {vb}    
Debug               {db}    
ErrorAction         {ea}    
WarningAction       {wa}    
InformationAction   {infa}  
ErrorVariable       {ev}    
WarningVariable     {wv}    
InformationVariable {iv}    
OutVariable         {ov}    
OutBuffer           {ob}    
PipelineVariable    {pv}    
WhatIf              {wi}    
Confirm             {cf}


Ejemplo
Arrancar una máquina virtual

PowerShell
1
Start-VM "MyNewVM"


Parar máquinas virtuales

Cmdlet

PowerShell
1
Stop-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CimSession          {}      
ComputerName        {}      
Credential          {}      
VM                  {}      
Name                {VMName}
Save                {}      
TurnOff             {}      
Force               {}      
AsJob               {}      
Passthru            {}      
Verbose             {vb}    
Debug               {db}    
ErrorAction         {ea}    
WarningAction       {wa}    
InformationAction   {infa}  
ErrorVariable       {ev}    
WarningVariable     {wv}    
InformationVariable {iv}    
OutVariable         {ov}    
OutBuffer           {ob}    
PipelineVariable    {pv}    
WhatIf              {wi}    
Confirm             {cf}


Ejemplo
Parar una máquina virtual

PowerShell
1
Stop-VM "MyNewVM"


Crear una instantánea

Cmdlet

PowerShell
1
Checkpoint-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CimSession          {}              
ComputerName        {}              
Credential          {}              
VM                  {}              
Name                {VMName}        
SnapshotName        {CheckpointName}
AsJob               {}              
Passthru            {}              
Verbose             {vb}            
Debug               {db}            
ErrorAction         {ea}            
WarningAction       {wa}            
InformationAction   {infa}          
ErrorVariable       {ev}            
WarningVariable     {wv}            
InformationVariable {iv}            
OutVariable         {ov}            
OutBuffer           {ob}            
PipelineVariable    {pv}            
WhatIf              {wi}            
Confirm             {cf}


Ejemplo
Crear una instantánea en la máquina virtual

PowerShell
1
Get-VM OR* | Checkpoint-VM


Ver las instantáneas de una máquina virtual

Cmdlet

PowerShell
1
Get-VMSnapshot

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
VMName              {}                    
VM                  {}                    
CimSession          {}                    
ComputerName        {}                    
Credential          {}                    
Id                  {}                    
Name                {}                    
ChildOf             {}                    
ParentOf            {}                    
SnapshotType        {VMRecoveryCheckpoint}
Verbose             {vb}                  
Debug               {db}                  
ErrorAction         {ea}                  
WarningAction       {wa}                  
InformationAction   {infa}                
ErrorVariable       {ev}                  
WarningVariable     {wv}                  
InformationVariable {iv}                  
OutVariable         {ov}                  
OutBuffer           {ob}                  
PipelineVariable    {pv}


Ejemplo
Ver las instantáneas de una máquina virtual

PowerShell
1
Get-VM "OR*" | Get-VMSnapshot


Eliminar una máquina virtual

Cmdlet

PowerShell
1
Remove-VM

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CimSession          {}      
ComputerName        {}      
Credential          {}      
Name                {VMName}
VM                  {}      
Force               {}      
AsJob               {}      
Passthru            {}      
Verbose             {vb}    
Debug               {db}    
ErrorAction         {ea}    
WarningAction       {wa}    
InformationAction   {infa}  
ErrorVariable       {ev}    
WarningVariable     {wv}    
InformationVariable {iv}    
OutVariable         {ov}    
OutBuffer           {ob}    
PipelineVariable    {pv}    
WhatIf              {wi}    
Confirm             {cf}


Ejemplo
Eliminar una máquina virtual

PowerShell
1
Remove-VM "MyNewVM"


Gestión de discos virtuales

Cmdlet

PowerShell
1
New-VHD

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Path                    {}      
ParentPath              {}      
SizeBytes               {}      
SourceDisk              {Number}
Dynamic                 {}      
Fixed                   {}      
Differencing            {}      
BlockSizeBytes          {}      
LogicalSectorSizeBytes  {}      
PhysicalSectorSizeBytes {}      
AsJob                   {}      
CimSession              {}      
ComputerName            {}      
Credential              {}      
Verbose                 {vb}    
Debug                   {db}    
ErrorAction             {ea}    
WarningAction           {wa}    
InformationAction       {infa}  
ErrorVariable           {ev}    
WarningVariable         {wv}    
InformationVariable     {iv}    
OutVariable             {ov}    
OutBuffer               {ob}    
PipelineVariable        {pv}    
WhatIf                  {wi}    
Confirm                 {cf}


Ejemplos
Crear un disco virtual de tamaño dinámico

PowerShell
1
New-VHD -Path "d:\MyNewDynamicVHDX.vhdx" -SizeBytes 127GB

Crear un disco virtual de tamaño fijo

PowerShell
1
New-VHD -Path "d:\MyNewFixedVHDX.vhdx" -Fixed -SizeBytes 20GB


Añadir un disco virtual a una máquina virtual

Cmdlet

PowerShell
1
Add-VMHardDiskDrive

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
CimSession                    {}                
ComputerName                  {PSComputerName}  
Credential                    {}                
VMName                        {}                
VM                            {}                
VMDriveController             {}                
ControllerType                {}                
ControllerNumber              {}                
ControllerLocation            {}                
Path                          {}                
DiskNumber                    {Number}          
ResourcePoolName              {}                
SupportPersistentReservations {ShareVirtualDisk}
AllowUnverifiedPaths          {}                
MaximumIOPS                   {}                
MinimumIOPS                   {}                
QoSPolicyID                   {}                
QoSPolicy                     {}                
Passthru                      {}                
OverrideCacheAttributes       {}                
Verbose                       {vb}              
Debug                         {db}              
ErrorAction                   {ea}              
WarningAction                 {wa}              
InformationAction             {infa}            
ErrorVariable                 {ev}              
WarningVariable               {wv}              
InformationVariable           {iv}              
OutVariable                   {ov}              
OutBuffer                     {ob}              
PipelineVariable              {pv}              
WhatIf                        {wi}              
Confirm                       {cf}


Ejemplo
Añadir un disco virtual a una máquina virtual

PowerShell
1
Add-VMHardDiskDrive -VMName "MyNewVM" -Path "d:\MyNewDynamicVHDX.vhdx"


Gestión de red virtual

Cmdlet

PowerShell
1
New-VMSwitch

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CimSession                     {}                    
ComputerName                   {PSComputerName}      
Credential                     {}                    
Name                           {SwitchName}          
SwitchType                     {}                    
AllowManagementOS              {}                    
NetAdapterName                 {InterfaceAlias}      
NetAdapterInterfaceDescription {InterfaceDescription}
Notes                          {}                    
MinimumBandwidthMode           {}                    
EnableIov                      {}                    
EnablePacketDirect             {}                    
EnableEmbeddedTeaming          {}                    
Verbose                        {vb}                  
Debug                          {db}                  
ErrorAction                    {ea}                  
WarningAction                  {wa}                  
InformationAction              {infa}                
ErrorVariable                  {ev}                  
WarningVariable                {wv}                  
InformationVariable            {iv}                  
OutVariable                    {ov}                  
OutBuffer                      {ob}                  
PipelineVariable               {pv}                  
WhatIf                         {wi}                  
Confirm                        {cf}


Ejemplo
Crear un switch virtual

PowerShell
1
New-VMSwitch "MyNewPrivateSwitch" -SwitchType Private -Notes "Private virtual switch"


Ver información sobre la red virtual

Cmdlet

PowerShell
1
Get-NetAdapter

Parámetros y alias de los parámetros para el cmdlet

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Name                 {ifAlias, InterfaceAlias}
InterfaceDescription {ifDesc}                
InterfaceIndex       {ifIndex}                
IncludeHidden        {}                      
Physical             {}                      
CimSession           {Session}                
ThrottleLimit        {}                      
AsJob                {}                      
Verbose              {vb}                    
Debug                {db}                    
ErrorAction          {ea}                    
WarningAction        {wa}                    
InformationAction    {infa}                  
ErrorVariable        {ev}                    
WarningVariable      {wv}                    
InformationVariable  {iv}                    
OutVariable          {ov}                    
OutBuffer            {ob}                    
PipelineVariable     {pv}


Ejemplo
Ver información sobre la red virtual

PowerShell
1
Get-NetAdapter -Name * | Format-List -Property Name, InterfaceDescription, InterfaceName


Publicado el día 6 de julio de 2017

CATEGORÍAS

PowerShell

ETIQUETAS

App, APT, Boot, bug, Curso, Cursos, diff, Drive, expand, ExpandProperty, find, Física, Format-List, Get-Command, Get-NetAdapter, hardware, hd, Herramientas, Hyper-V, iOS, IP, ISO, Jesús Niño Camazón, Libro PowerShell nivel intermedio, Log, Mac, Metro, Microsoft, Module, move, mv, NAP, New-VHD, New-VM, Nmap, Path, Paths, Pin, ping, Recover, Remove, routing, Script, Select-Object, Server, Sistema Operativo, size, SNAP, Software, Source, switch, USB, Version, Virtual, Virtualización, VLAN

MÁS

  • Libro de PowerShell (nivel avanzado), (libro online de PowerShell), (tutorial gratis de PowerShell)
  • Cómo depurar scripts en ISE de Windows PowerShell
  • Obtener información sobre el hardware de un equipo creando un objeto y convertirlo en JSON y después lo convierte a código QR, por último comprueba y lee el código QR generado
  • La "super" librería user32.dll
  • 13. Interfaces de usuario gráficas en PowerShell (nivel intermedio)
  • Distintas formas de ejecutar el bucle ForEach en PowerShell
Jesusninoc utiliza cookies: saber más aquí.