netclient-install.ps1 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. new-module -name netclient-install -scriptblock {
  2. function Quit {
  3. param(
  4. $Text
  5. )
  6. Write-Host "Exiting: " $Text
  7. Break Script
  8. }
  9. Function Netclient-Install() {
  10. param ($version='latest', $token)
  11. if($token -eq $null -or $token -eq ""){
  12. Quit "-token required"
  13. }
  14. $software = "WireGuard";
  15. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  16. If(-Not $installed) {
  17. Write-Host "'$software' is NOT installed. installing...";
  18. $url = "https://download.wireguard.com/windows-client/wireguard-installer.exe"
  19. $outpath = "$env:userprofile\Downloads\wireguard-installer.exe"
  20. Invoke-WebRequest -Uri $url -OutFile $outpath
  21. $args = @("Comma","Separated","Arguments")
  22. $procWG = Start-Process -Filepath "$env:userprofile\Downloads\wireguard-installer.exe" -ArgumentList $args
  23. $procWG.WaitForExit()
  24. Start-Sleep -Seconds 5
  25. $software = "WireGuard";
  26. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  27. If(-Not $installed) {
  28. Quit "Could not install WireGuard"
  29. } else {
  30. Write-Host "'$software' is installed."
  31. }
  32. } else {
  33. Write-Host "'$software' is installed."
  34. }
  35. $outpath = "";
  36. if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
  37. $outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
  38. } else {
  39. $outpath = "$env:userprofile\Downloads\netclient.exe"
  40. Write-Host "'netclient.exe' is NOT installed. installing...";
  41. Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
  42. $url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
  43. Invoke-WebRequest -Uri $url -OutFile $outpath
  44. }
  45. $NetArgs = @("join","-t",$token)
  46. $procNC = Start-Process -Filepath $outpath -ArgumentList $NetArgs
  47. $procNC.WaitForExit()
  48. Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
  49. if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
  50. if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
  51. New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
  52. Move-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
  53. $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
  54. $newpath = "$oldpath;C:\ProgramData\Netclient\bin"
  55. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  56. $env:Path += ";C:\ProgramData\Netclient\bin"
  57. }
  58. '''
  59. Please add netclient.exe to your path to make it permanently executable from powershell:
  60. 1. Open "Edit environment variables for your account"
  61. 2. Double click on "Path"
  62. 3. On a new line, add the following: C:\ProgramData\Netclient\bin
  63. 4. Click "Ok"
  64. '''
  65. }
  66. Write-Host "'netclient' is installed."
  67. }
  68. }