netclient-install.ps1 3.3 KB

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