-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathvmconnect.ps1
42 lines (34 loc) · 1.04 KB
/
vmconnect.ps1
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
38
39
40
41
42
function Start-VMConnect
{
[CmdletBinding()]
param
(
# CMDLet takes a single parameter of VMNames.
# Can be single or plural, can come from the pipeline.
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]$VMnames
)
begin
{
# Path to the binary for FreeRDP
$FreeRDPPath = "C:\FreeRDP\wfreerdp.exe"
}
process
{
foreach ($VMname in $VMnames)
{
if ($pscmdlet.ShouldProcess($VMname))
{
# Get the ID of the virtual machine
# If a VM object has been provided - grab the ID directly
# Otherwise, try and get the VM object and get the ID from there
if ($VMname.GetType().name -eq "VirtualMachine")
{$VMID = $VMname.ID}
else
{$VMID = (get-vm $VMname | Select-Object -first 1).ID}
# Start FreeRDP
start-process $FreeRDPPath -ArgumentList "/v:localhost:2179 /vmconnect:$($VMID)"
}
}
}
end {}
}