-
Notifications
You must be signed in to change notification settings - Fork 0
/
VM
86 lines (80 loc) · 1.52 KB
/
VM
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/pwsh
. "connected.ps1" $args[$args.count-1]
$item = $args[0]
$vm = $args[1]
switch($item)
{
Start
{
if($vm.indexOf(",") -gt 0 )
{
$svm=$vm.Split(",")
for($i=0;$i -lt $svm.count;$i++)
{
Start-VM $svm[$i]
}
}
else
{
Start-VM $vm
}
}
#------------
Stop
{
if($vm.indexOf(",") -gt 0 )
{
$svm=$vm.Split(",")
for($i=0;$i -lt $svm.count;$i++)
{
Stop-VM $svm[$i] -Confirm:$false
}
}
else
{
Stop-VM $vm -Confirm:$false
}
}
#------------
List
{
if($args.count -eq 2)
{
Get-VM | Format-Table -property Name,PowerState
}
else
{
if($vm.indexOf(",") -gt 0 )
{
$svm = $vm.Split(",")
for($i=0; $i -lt $svm.count; $i++)
{
Get-VM -Name $svm[$i]
}
}
else
{
Get-VM -Name $vm
}
}
}
#------------
remove
{
if($vm.indexOf(",") -gt 0 )
{
$svm=$vm.Split(",")
for($i=0;$i -lt $svm.count;$i++)
{
$vmr = Get-VM -Name $svm[$i]
if ($vmr.PowerState -ne 'PoweredOff') { $vmr | Stop-VM -Confirm:$false | Out-Null }
Remove-VM $vmr -DeletePermanently -Confirm:$false
}
}
else
{
Remove-VM $vm -DeletePermanently -Confirm:$false
}
}
#------------
}