netclient-install.ps1 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if ($procWG -eq $null) {}
  24. Start-Sleep -Seconds 5
  25. } else {
  26. $procWG.WaitForExit()
  27. }
  28. $procWG.WaitForExit()
  29. Start-Sleep -Seconds 5
  30. $software = "WireGuard";
  31. $installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
  32. If(-Not $installed) {
  33. Quit "Could not install WireGuard"
  34. } else {
  35. Write-Host "'$software' is installed."
  36. }
  37. } else {
  38. Write-Host "'$software' is installed."
  39. }
  40. $outpath = "";
  41. if (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe") {
  42. $outpath = "C:\ProgramData\Netclient\bin\netclient.exe";
  43. } else {
  44. $outpath = "$env:userprofile\Downloads\netclient.exe"
  45. Write-Host "'netclient.exe' is NOT installed. installing...";
  46. Write-Host "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe";
  47. $url = "https://github.com/gravitl/netmaker/releases/download/$version/netclient.exe"
  48. Invoke-WebRequest -Uri $url -OutFile $outpath
  49. }
  50. $NetArgs = @("join","-t",$token)
  51. $procNC = Start-Process -Filepath $outpath -ArgumentList $NetArgs
  52. if ($procNC -eq $null) {}
  53. Start-Sleep -Seconds 5
  54. } else {
  55. $procNC.WaitForExit()
  56. }
  57. Add-MpPreference -ExclusionPath "C:\ProgramData\Netclient"
  58. if ((Get-Command "netclient.exe" -ErrorAction SilentlyContinue) -eq $null) {
  59. if (-not (Test-Path -Path "C:\ProgramData\Netclient\bin\netclient.exe")) {
  60. New-Item -Path "C:\ProgramData\Netclient" -Name "bin" -ItemType "directory"
  61. Move-Item -Path "$env:userprofile\Downloads\netclient.exe" -Destination "C:\ProgramData\Netclient\bin\netclient.exe"
  62. $oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
  63. $newpath = "$oldpath;C:\ProgramData\Netclient\bin"
  64. Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
  65. $env:Path += ";C:\ProgramData\Netclient\bin"
  66. }
  67. '''
  68. Please add netclient.exe to your path to make it permanently executable from powershell:
  69. 1. Open "Edit environment variables for your account"
  70. 2. Double click on "Path"
  71. 3. On a new line, add the following: C:\ProgramData\Netclient\bin
  72. 4. Click "Ok"
  73. '''
  74. }
  75. Write-Host "'netclient' is installed."
  76. }
  77. }