¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 58°Ç
   
[POWERSHELL] Connect-VM
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2013-08-28 (¼ö) 11:44 Á¶È¸ : 4511
±ÛÁÖ¼Ò :
                          

http://www.powershellmagazine.com/2012/10/11/connecting-to-hyper-v-virtual-machines-with-powershell/




#requires -Version 3.0 function Connect-VM { [CmdletBinding(DefaultParameterSetName='name')] param( [Parameter(ParameterSetName='name')] [Alias('cn')] [System.String[]]$ComputerName=$env:COMPUTERNAME, [Parameter(Position=0, Mandatory,ValueFromPipelineByPropertyName, ValueFromPipeline,ParameterSetName='name')] [Alias('VMName')] [System.String]$Name, [Parameter(Position=0, Mandatory,ValueFromPipelineByPropertyName, ValueFromPipeline,ParameterSetName='id')] [Alias('VMId','Guid')] [System.Guid]$Id, [Parameter(Position=0,Mandatory, ValueFromPipeline,ParameterSetName='inputObject')] [Microsoft.HyperV.PowerShell.VirtualMachine]$InputObject, [switch]$StartVM ) begin { Write-Verbose "Initializing InstanceCount, InstanceCount = 0" $InstanceCount=0 } process { try { foreach($computer in $ComputerName) { Write-Verbose "ParameterSetName is '$($PSCmdlet.ParameterSetName)'" if($PSCmdlet.ParameterSetName -eq 'name') { # Get the VM by Id if Name can convert to a guid if($Name -as [guid]) { Write-Verbose "Incoming value can cast to guid" $vm = Get-VM -Id $Name -ErrorAction SilentlyContinue } else { $vm = Get-VM -Name $Name -ErrorAction SilentlyContinue } } elseif($PSCmdlet.ParameterSetName -eq 'id') { $vm = Get-VM -Id $Id -ErrorAction SilentlyContinue } else { $vm = $InputObject } if($vm) { Write-Verbose "Executing 'vmconnect.exe $computer $($vm.Name) -G $($vm.Id) -C $InstanceCount'" vmconnect.exe $computer $vm.Name -G $vm.Id -C $InstanceCount } else { Write-Verbose "Cannot find vm: '$Name'" } if($StartVM -and $vm) { if($vm.State -eq 'off') { Write-Verbose "StartVM was specified and VM state is 'off'. Starting VM '$($vm.Name)'" Start-VM -VM $vm } else { Write-Verbose "Starting VM '$($vm.Name)'. Skipping, VM is not not in 'off' state." } } $InstanceCount+=1 Write-Verbose "InstanceCount = $InstanceCount" } } catch { Write-Error $_ } } }

À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.