Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.3 kB
2
Indexable
Never
Import-Module -Name "C:\Program Files\Intel\Wired Networking\IntelNetCmdlets\IntelNetCmdlets"
$staticIP = "10.10.30.10"
$gateway = "10.10.30.1"
$currentVLANCount = (Get-IntelNetVLAN | Where-Object {$_.VLANID -eq 30 -or $_.VLANID -eq 0} | Measure-Object).Count
echo "vlancount : $currentVLANCount"
#Assume 0 VLANs -> create the VLANs we need
if ($currentVLANCount -eq 0){
  $adapter = Get-IntelNetAdapter
  
  #Creating a new vSwitch
  New-VMSwitch -name VLAN-vSwitch -NetAdapterName Ethernet -AllowManagementOS $true
  echo "adapter : $($adapter.name)"

  #Add-IntelNetVLAN -ParentName $adapter.name -VLANID "30"
  Add-VMNetworkAdapter -ManagementOS -Name $adapter.name -SwitchName "VLAN-vSwitch" -Passthru | Set-VMNetworkAdapterVlan -Access -VlanId 30

  #Add-IntelNetVLAN -ParentName $adapter.name -VLANID "0"
  Add-VMNetworkAdapter -ManagementOS -Name $adapter.name -SwitchName "VLAN-vSwitch" -Passthru | Set-VMNetworkAdapterVlan -Access -VlanId 0
}
echo "vlans created"
#get the second latest Ethernet interface, should correspond to VLANID 30
$interface =(Get-NetIpInterface | Where-Object {$_.InterfaceAlias -Match "^Ethernet" -and $_.AddressFamily -eq "IPv4"} | Sort-Object -Property InterfaceAlias -Descending | Select-Object -Index 1)

netsh interface ip set address $interface.InterfaceAlias static $staticIP 255.255.255.0 $gateway
netsh interface ip set dns $interface.InterfaceAlias static 1.1.1.1
netsh interface ip add dns $interface.InterfaceAlias 8.8.8.8 index=2

#open firewall port for MQTT traffic
if (!(Get-NetFirewallRule -DisplayName 'MQTTPort')){
  New-NetFirewallRule -DisplayName 'MQTTPort' -Profile 'Private','Public','Domain' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 1883
}
#allow Tagsurance 3 through firewall
if(!(Get-NetFirewallRule -DisplayName 'Tagsurance 3')){
  New-NetFirewallRule -DisplayName "Tagsurance 3" -Direction Inbound -Program "C:\Tagsurance 3\Tagsurance 3.exe" -Action Allow
}

#allow Node.js through firewall
if(!(Get-NetFirewallRule -DisplayName 'Node')){
  New-NetFirewallRule -DisplayName "Node" -Direction Inbound -Program "C:\Program Files\nodejs\node.exe" -Action Allow
}

#disable WiFi, hoping it is named Wi-Fi as it has been for NUCs
netsh interface set interface Wi-Fi disable
Leave a Comment