-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVMwareScript.ps1
74 lines (61 loc) · 2.16 KB
/
VMwareScript.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
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
<#
.DESCRIPTION
Script to enable or disable required VMWare services, autolaunch specific VMs
.PARAMETER AutoLaunch
Autolaunch specified VMs
.EXAMPLE
.\VMWareScript.ps1 -AutoLaunch fedora
.EXAMPLE
.\VMWareScript.ps1 -AutoLaunch arch
.EXAMPLE
Get-Help .\VMWareScript.ps1
.SYNOPSIS
Autolaunch specified VMs.
Enable or Disable VMWare services.
#>
#! Parameter help description
param(
[Parameter(ParameterSetName = "AutoLaunch")]
[ValidateSet(
"fedora",
"arch",
"kali"
)]
[String] $AutoLaunch
)
#! Autolaunch VMs
if ($AutoLaunch -eq "fedora") {
& "${env:ProgramFiles(x86)}\VMware\VMware Workstation\vmrun.exe" -T ws start "${env:USERPROFILE}\Downloads\VMWare\FedoraLinux\Fedora Linux.vmx"
} elseif ($AutoLaunch -eq "arch") {
& "${env:ProgramFiles(x86)}\VMware\VMware Workstation\vmrun.exe" -T ws start "${env:USERPROFILE}\Downloads\VMWare\ArchLinux\Arch Linux.vmx"
} elseif ($AutoLaunch -eq "kali") {
& "${env:ProgramFiles(x86)}\VMware\VMware Workstation\vmrun.exe" -T ws start "${env:USERPROFILE}\Downloads\VMWare\KaliLinux\Kali Linux.vmx"
}
#! Start or Stop VMware Workstation program
# $VMWareProcess = Get-Process vmplayer -ErrorAction SilentlyContinue
# if (!$VMWareProcess) {
# Write-Host "Start VMWare Workstation Player."
# Start-Process -FilePath "${env:ProgramFiles(x86)}\VMware\VMware Workstation\vmplayer.exe"
# }
# elseif ($VMWareProcess) {
# Write-Host "Stop VMWare Worksation Player."
# $VMWareProcess | Stop-Process -Force
# }
#! Enable or Disable required services
$Services = @("VMware DHCP Service", "VMware NAT Service", "VMware USB Arbitration Service")
foreach ($Service in $Services) {
$ServiceName = Get-Service -Name $Service
$ServiceStatus = (Get-Service -Name $Service).Status
$ServiceDisplayName = (Get-Service -Name $Service).DisplayName
if ($ServiceStatus -eq "Running") {
Write-Host "Stop ${ServiceDisplayName}."
Stop-Service $ServiceName
}
elseif ($ServiceStatus -eq "Stopped") {
Write-Host "Start ${ServiceDisplayName}."
Start-Service $ServiceName
}
else {
Write-Host "${ServiceDisplayName} is not running or stopped."
}
}