# encoding: ascii
# api: powershell
# title: Test-VM
# description: This function is prepared for Hyper-V 3.0 since we don’t have a native cmdlet in the module.
# version: 0.1
# type: function
# author: Huajun Gu
# license: CC0
# function: Test-VM
# x-poshcode-id: 3482
# x-archived: 2012-06-30T22:15:04
# x-published: 2012-06-25T17:40:00
#
#
Function Test-VM
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory=$true,Position=1)]
[string[]]$Name,
[Parameter(Mandatory=$true,Position=2)]
[string[]]$ComputerName
)
Process
{
$results = @()
foreach ($cName in $ComputerName) {
foreach ($vName in $Name) {
$result = New-Object System.Management.Automation.PSObject
Try
{
$vm = Get-VM -ComputerName $cName -Name $vName -ErrorAction Stop
}
Catch
{
#Display an error message
}
if ($vm -ne $null) {
$Existence = $true
} else {
$Existence = $false
}
$result | Add-Member -NotePropertyName ComputerName -NotePropertyValue $cName
$result | Add-Member -NotePropertyName Name -NotePropertyValue $vName
$result | Add-Member -NotePropertyName Existence -NotePropertyValue $Existence
$results += $result
}
}
return $results
}
}