1
1
Set-StrictMode - Version 2
2
2
$ErrorActionPreference = ' Stop'
3
3
4
- try {
5
- New-VMSwitch - name MultipassSwitch - NetAdapterName Ethernet - AllowManagementOS $true
6
- }
7
- catch {
8
- if ($_.Exception.Message -notmatch " already bound" ) {
9
- Write-Output $_
10
- exit 1
4
+ if (-not (Get-Command multipass.exe - ErrorAction SilentlyContinue)) {
5
+ $url = " https://multipass.run/download/windows"
6
+ $dirPath = " C:\Temp"
7
+ if (-Not (Test-Path $dirPath )) {
8
+ New-Item - ItemType Directory - Path $dirPath
11
9
}
10
+ $filePath = " $dirPath \Multipass-Installer.exe"
11
+ Write-Output " Downloading Multipass from $url to $filePath "
12
+ Invoke-WebRequest - Uri $url - OutFile $filePath
13
+ # Install Multipass silently
14
+ Write-Output " Installing Multipass from $filePath "
15
+ Start-Process - FilePath $filePath - Args " /S" - Wait
16
+ Write-Output " Installed Multipass"
12
17
}
13
18
14
19
$hostname = $env: COMPUTERNAME.ToLower ()
@@ -76,42 +81,42 @@ function Wait-ForMultipassd {
76
81
77
82
Wait-ForMultipassd
78
83
79
- # Write-Output "Setting local.passphrase"
80
- # multipass.exe set local.passphrase=foo
81
- # if ($LASTEXITCODE -ne 0) {
82
- # Write-Output "Failed to set local.passphrase"
83
- # exit $LASTEXITCODE
84
- # }
85
-
86
- # Wait-ForMultipassd
87
- # Write-Output "Setting local.bridged-network"
88
- # multipass.exe set local.bridged-network=MultipassSwitch
89
- # if ($LASTEXITCODE -ne 0) {
90
- # Write-Output "Failed to set local.bridged-network"
91
- # exit $LASTEXITCODE
92
- # }
93
-
94
- # # # Wait-ForMultipassd
95
- # Write-Output "Getting ethernet IP"
96
- # try {
97
- # $ethIp = (Get-NetIPAddress -InterfaceAlias "vEthernet (MultipassSwitch)" -AddressFamily IPv4).IPAddress
98
- # }
99
- # catch {
100
- # Write-Output "Failed to get ethernet IP"
101
- # Write-Output $_
102
- # exit 1
103
- # }
104
-
105
- # Write-Output "Found ethernet IP: $ethIp"
106
-
107
- # Write-Output "Going to add portproxy rule for $($ethIp):$($multipassdPort)"
108
- # netsh interface portproxy add v4tov4 listenport=$multipassdPort listenaddress=$ethIp connectport=$multipassdPort connectaddress=127.0.0.1
109
- # if ($LASTEXITCODE -ne 0) {
110
- # exit $LASTEXITCODE
111
- # }
112
-
113
- # Write-Output "Going to add firewall rule for $($ethIp):$($multipassdPort)"
114
- # New-NetFirewallRule -DisplayName "multipassd_51000" -Direction Inbound -Protocol TCP -LocalPort $multipassdPort -Action Allow -PolicyStore PersistentStore
115
- # if ($LASTEXITCODE -ne 0) {
116
- # exit $LASTEXITCODE
117
- # }
84
+ Write-Output " Setting local.passphrase"
85
+ multipass.exe set local.passphrase= foo
86
+ if ($LASTEXITCODE -ne 0 ) {
87
+ Write-Output " Failed to set local.passphrase"
88
+ exit $LASTEXITCODE
89
+ }
90
+
91
+ Wait-ForMultipassd
92
+ Write-Output " Setting local.bridged-network"
93
+ multipass.exe set local.bridged- network= MultipassSwitch
94
+ if ($LASTEXITCODE -ne 0 ) {
95
+ Write-Output " Failed to set local.bridged-network"
96
+ exit $LASTEXITCODE
97
+ }
98
+
99
+ # # Wait-ForMultipassd
100
+ Write-Output " Getting ethernet IP"
101
+ try {
102
+ $ethIp = (Get-NetIPAddress - InterfaceAlias " vEthernet (MultipassSwitch)" - AddressFamily IPv4).IPAddress
103
+ }
104
+ catch {
105
+ Write-Output " Failed to get ethernet IP"
106
+ Write-Output $_
107
+ exit 1
108
+ }
109
+
110
+ Write-Output " Found ethernet IP: $ethIp "
111
+
112
+ Write-Output " Going to add portproxy rule for $ ( $ethIp ) :$ ( $multipassdPort ) "
113
+ netsh interface portproxy add v4tov4 listenport= $multipassdPort listenaddress= $ethIp connectport= $multipassdPort connectaddress= 127.0 .0.1
114
+ if ($LASTEXITCODE -ne 0 ) {
115
+ exit $LASTEXITCODE
116
+ }
117
+
118
+ Write-Output " Going to add firewall rule for $ ( $ethIp ) :$ ( $multipassdPort ) "
119
+ New-NetFirewallRule - DisplayName " multipassd_51000" - Direction Inbound - Protocol TCP - LocalPort $multipassdPort - Action Allow - PolicyStore PersistentStore
120
+ if ($LASTEXITCODE -ne 0 ) {
121
+ exit $LASTEXITCODE
122
+ }
0 commit comments