Herausforderung war eine VPN Verbidung während des Deploymentprozesses mit zu installieren.
Dafür bietet sich auf jeden Fall ein PowershellScript an.
Bei uns handelt es sich um eine Microsoft VPN-Verbindung

Grundsätzlich werden verschiedene Paramenter berücksichtigt.
1) Bin ich ein Laptop und es soll VPN installiert werden (bei Desktops nicht)
2) Welcher Standort (unterscheidung anhand des Names)

View source
  1.  
  2.  
  3.  
  4.  
  5. <#
  6. .NOTES
  7. ===========================================================================
  8. Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.127
  9. Created on: 25.08.2016 09:44
  10. Created by: admin
  11. Organization: Commandline.info
  12. Filename:
  13. ===========================================================================
  14. .DESCRIPTION
  15. A description of the file.
  16. #>
  17. # Getting Global Parameters
  18. $computername = $env:COMPUTERNAME
  19. $VPNName = "My VPN 2.0"
  20. $VPNServer = $computername
  21. $Serveraddress = ""
  22. $ProxyServer = ""
  23.  
  24.  
  25.  
  26. function check-chassis {
  27. BEGIN {}
  28. PROCESS {
  29. $computer = $computername
  30. $chassis = Get-WmiObject win32_systemenclosure -computer $computer | select chassistypes
  31. if ($chassis.chassistypes -contains '3'){Write-Output "Desktop"}
  32. elseif ($chassis.chassistypes -contains '4'){Write-Output "Low Profile Desktop"}
  33. elseif ($chassis.chassistypes -contains '5'){Write-Output "Pizza Box"}
  34. elseif ($chassis.chassistypes -contains '6'){Write-Output "Mini Tower"}
  35. elseif ($chassis.chassistypes -contains '7'){Write-Output "Tower"}
  36. elseif ($chassis.chassistypes -contains '8'){Write-Output "Portable"}
  37. elseif ($chassis.chassistypes -contains '9'){Write-Output "Laptop"}
  38. elseif ($chassis.chassistypes -contains '10'){Write-Output "Notebook"}
  39. elseif ($chassis.chassistypes -contains '11'){Write-Output "Hand Held"}
  40. elseif ($chassis.chassistypes -contains '12'){Write-Output "Docking Station"}
  41. elseif ($chassis.chassistypes -contains '13'){Write-Output "All in One"}
  42. elseif ($chassis.chassistypes -contains '14'){Write-Output "Sub Notebook"}
  43. elseif ($chassis.chassistypes -contains '15'){Write-Output "Space-Saving"}
  44. elseif ($chassis.chassistypes -contains '16'){Write-Output "Lunch Box"}
  45. elseif ($chassis.chassistypes -contains '17'){Write-Output "Main System Chassis"}
  46. elseif ($chassis.chassistypes -contains '18'){Write-Output "Expansion Chassis"}
  47. elseif ($chassis.chassistypes -contains '19'){Write-Output "Sub Chassis"}
  48. elseif ($chassis.chassistypes -contains '20'){Write-Output "Bus Expansion Chassis"}
  49. elseif ($chassis.chassistypes -contains '21'){Write-Output "Peripheral Chassis"}
  50. elseif ($chassis.chassistypes -contains '22'){Write-Output "Storage Chassis"}
  51. elseif ($chassis.chassistypes -contains '23'){Write-Output "Rack Mount Chassis"}
  52. elseif ($chassis.chassistypes -contains '24'){Write-Output "Sealed-Case PC"}
  53. else {Write-output "Unknown"}
  54.  
  55. }
  56. END{}
  57. }
  58.  
  59. $chassis = check-chassis
  60.  
  61.  
  62.  
  63. switch -wildcard ($VPNServer)
  64. {
  65. "NBWG*" { $Serveraddress = "ServerHamburg.commandline.info"; $ProxyServer = "ProxyHamburg.commandline.info:8080"}
  66. "NBMUK*" { $Serveraddress = "ServerHamburg.commandline.info"; $ProxyServer = "ProxyHamburg.commandline.info:8080" }
  67. "NBMFR*" { $Serveraddress = "ServerHamburg.commandline.info"; $ProxyServer = "ProxyHamburg.commandline.info:8080" }
  68. "NBWGSH*" { $Serveraddress = "ServerChina.commandline.info"; $ProxyServer = "Proxychina.commandline.info:8080" }
  69. default { $Serveraddress = "ServerHamburg.commandline.info"; $ProxyServer = "ProxyHamburg.commandline.info:8080" }
  70. }
  71.  
  72.  
  73.  
  74. If ($chassis -eq "Portable" -Or $chassis -eq "Laptop" -Or $chassis -eq "Notebook" -Or $chassis -eq "Docking Station" -Or $chassis -eq "Sub Notebook") {
  75. Add-VpnConnection -Name "$VPNName" -ServerAddress "$Serveraddress" -TunnelType SSTP -Encryptionlevel Required -AuthenticationMethod MSChapv2 -UseWinlogonCredential -SplitTunneling -AllUserConnection -RememberCredential -PassThru
  76. Set-VpnConnectionProxy -Name "$VPNName" -ProxyServer "$ProxyServer" -BypassProxyForLocal
  77. #Optional Copy an Lnk to VPN to Desktop
  78. #Copy-Item $PSScriptRoot\Links\*.lnk -destination $env:Public\Desktop
  79. }
  80. Else
  81. {
  82. Exit 0
  83. }
  84.  
  85.  
  86.