hi all,
i need help with my problem. I found script that can connect to VPN with powershell, but i am lazy :) and i have four vpn profiles with crazy log passwords and i can secure save it and when script will conecting to vpn secure read it from file.
here is script to connect to vpn
#This script is tested with "Cisco AnyConnect Secure Mobility Client version 3.1.10010"
#Please change following variables
#IP address or host name of cisco vpn
[string]$CiscoVPNHost = “vpn.domain.local"
[string]$Login = domain\username
[string]$Password = password
[string]$agree = "y"
#Please check if file exists on following paths
[string]$vpncliAbsolutePath = 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe'
[string]$vpnuiAbsolutePath = 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe'
#****************************************************************************
#**** Please do not modify code below unless you know what you are doing ****
#****************************************************************************
Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
#Set foreground window function
#This function is called in VPNConnect
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class Win {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
'@ -ErrorAction Stop
#quickly start VPN
#This function is called later in the code
Function VPNConnect()
{
Start-Process -FilePath $vpncliAbsolutePath -ArgumentList "connect $CiscoVPNHost"
$counter = 0; $h = 0;
while($counter++ -lt 1000 -and $h -eq 0)
{
sleep -m 10
$h = (Get-Process vpncli).MainWindowHandle
}
#if it takes more than 10 seconds then display message
if($h -eq 0){echo "Could not start VPNUI it takes too long."}
else{[void] [Win]::SetForegroundWindow($h)}
}
#Check if VPN is running, but disconnected, and if so, kill the process so we can reconnect.
if (("$vpncliAbsolutePath state") -like "*Disconnected*") {
#Terminate all vpnui processes.
Get-Process | ForEach-Object {if($_.ProcessName.ToLower() -eq "vpnui")
{$Id = $_.Id; Stop-Process $Id; echo "Process vpnui with id: $Id was stopped"}}
#Terminate all vpncli processes.
Get-Process | ForEach-Object {if($_.ProcessName.ToLower() -eq "vpncli")
{$Id = $_.Id; Stop-Process $Id; echo "Process vpncli with id: $Id was stopped"}}
}
#Connect to VPN
echo "Connecting to VPN address '$CiscoVPNHost' as user '$Login'."
VPNConnect
#Write login and password
[System.Windows.Forms.SendKeys]::SendWait("$Login{Enter}")
[System.Windows.Forms.SendKeys]::SendWait("$Password{Enter}")
[System.Windows.Forms.SendKeys]::SendWait("$agree{Enter}")
and here i found script to secure save username and password to file and read them
$Path = "$home\Desktop\multipass.xml"
[PSCustomObject]@{
User1 = Get-Credential -Message User1
User2 = Get-Credential -Message User2
User3 = Get-Credential -Message User3
} | Export-Clixml -Path $Path
$multipass = Import-Clixml -Path $Path
but i try everything but i was not able to merge this two scripts
can you help me please?
Martin Hubka nework admin