Browsed by
Tag: PowerShell

How do I ?

How do I ?

My code editor of choice is Visual Studio Code and so far I found it very useful. It also has a PowerShell extension so I can run my scripts directly from within the Code Editor.

VS Code has a lot of themes from which you can choose but I prefer one theme for the editor and the classic blue and white theme for the terminal.

So if you are like me, you can quickly change the aspect of the terminal by:

  • Open the User Settings (Ctrl + , )
  • Go to Workbench->Appearance->Color Customization and click on “Edit in settings.json
  • Add the code below:
workbench.colorCustomizations": {
    "terminal.foreground": "#FFFFFF",
    "terminal.background": "#012456"
 }

Create a VPN Connection and change its settings with PowerShell. Windows 10

Create a VPN Connection and change its settings with PowerShell. Windows 10

I had to deploy a VPN connection in an environment which looks like this:

  • Domain Controller is hosted on a Virtual Machine in Azure
  • Using an Azure Virtual Network Gateway
  • Point-to-site configuration uses RADIUS authentication.

I accomplished this using the Windows administrator’s best friend, PowerShell.

The prerequisites for these are:

  • Get the VPN server IP/DNS
  • Make sure computers are using PowerShell 3.0

The Powershell script to deploy a VPN connection would look like this:

#Set Variables for the VPN connection
$VPNconnectionName = "New VPN"
$SRVaddress = "auzrevpn.azure.com"
$dnssuf = "contoso.com"

#Create the VPN connection
Add-VpnConnection -Name $VPNconnectionName -ServerAddress $SRVaddress -TunnelType Sstp -AuthenticationMethod Eap -EncryptionLevel Required -AllUserConnection -SplitTunneling -IdleDisconnectSeconds 900 -DnsSuffix $dnssuf

#Get the content from the phone book
$contain = Get-Content -Path "$env:ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk" -Raw

#Change the connection phone book content to add the internal DNS entries  
if ($contain.Contains("IpDnsAddress=0.0.0.0")){
($contain) -replace 'IpDnsAddress=0.0.0.0','IpDnsAddress=192.168.1.4' -replace 'IpDns2Address=0.0.0.0','IpDns2Address=192.168.1.10'-replace 'IpNameAssign=1','IpNameAssign=2'| Set-Content "$env:ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk"
}