SonicWallVpn.ps1
function Enable-SonicVpn { [CmdletBinding()] Param ( [string] $name = "VPN" ) Write-Verbose -Message "Connecting to VPN..." $user = Get-User $pwd = Get-Password & "C:\Program Files\Dell SonicWALL\Global VPN Client\swgvc.exe" /E $name /U $user /P $pwd } function Disable-SonicVpn { [CmdletBinding()] Param ( [string] $name = "VPN" ) Write-Verbose -Message "Disonnecting VPN..." & "C:\Program Files\Dell SonicWALL\Global VPN Client\swgvc.exe" /D $name } function Get-Password { $pwdFileName = "$(Get-ModulePath)\vpn.pwd" if(Test-Path -Path $pwdFileName) { $pwdFile = Get-Content -Path $pwdFileName $secured = $pwdFile | ConvertTo-SecureString } else { $secured = Read-Host -Prompt "Enter password for VPN" -AsSecureString $secured | ConvertFrom-SecureString | Out-File -FilePath $pwdFileName } $user=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name $creds = new-object -TypeName PSCredential -ArgumentList $user, $secured $pwd = $creds.GetNetworkCredential().Password return $pwd } function Get-User { $usrFileName = "$(Get-ModulePath)\vpn.usr" Write-Verbose -Message $usrFileName if(Test-Path -Path $usrFileName) { $usr = Get-Content -Path $usrFileName } else { $usr = Read-Host -Prompt "Enter user name for VPN" $usr | Out-File -FilePath $usrFileName } return $usr } function Get-ModulePath { Split-Path -Path "$PSScriptRoot\SonicWallVPN\" } New-Alias -Name evpn -Value Enable-SonicVpn Export-ModuleMember -Function Enable-SonicVpn -Alias evpn New-Alias -Name dvpn -Value Disable-SonicVpn Export-ModuleMember -Function Disable-SonicVpn -Alias dvpn |