Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module C:\Users\PAUL.CASTILLO3\Downloads\UIAutomation.0.8.7B3.NET40\UIAutomation.dll
- [UIAutomation.Preferences]::Highlight = $false
- [UIAutomation.Preferences]::Log = $false
- [UIAutomation.Preferences]::AutoLog = $false
- [UIAutomation.Preferences]::OnErrorScreenShot = $false
- $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
- function Connect-VPN() {
- $vpnUI = Get-Process | Where-Object {$_.Name -like "vpnui"}
- if($vpnUI){
- Write-Host "Found VPN process" -ForegroundColor Yellow
- Retrieve-VPN
- } else {
- #Write-Host "Need to start Cisco Client"
- $vpn = Start-Process -FilePath "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
- Retrieve-VPN
- }
- }
- function Disconnect-VPN(){
- $vpnUI = Get-Process | Where-Object {$_.Name -like "vpnui"}
- if($vpnUI){
- Write-Host "found it"
- $isVPNConnected = $true
- $vpnWin = Get-UiaWindow -Class '#32770' -Name 'Cisco AnyConnect Secure Mobility Client'
- if($vpnWin){
- Set-ForegroundWindow $vpnWin.Current.NativeWindowHandle
- }
- try {
- $vpnStart = $vpnWin | Get-UiaButton -Class 'Button' -Name 'Disconnect' -Win32
- } catch {
- }
- if($vpnStart) {
- $vpnStart.Invoke()
- Write-Host "Disconnected from VPN"
- } else {
- Write-Host "VPN is not connected."
- }
- }
- }
- function Retrieve-VPN {
- $vpnWin = Get-UiaWindow -Class '#32770' -Name 'Cisco AnyConnect Secure Mobility Client'
- if($vpnWin){
- Set-ForegroundWindow $vpnWin.Current.NativeWindowHandle
- } else {
- Write-Host "unable to find VPN process"
- break
- }
- $vpnStart = $vpnWin | Get-UiaButton -Class 'Button' -Name 'Connect' -Win32
- $vpnStart.Invoke()
- Start-Sleep -s 3
- $winSecurity = Get-UiaWindow -Class '#32770' -Name 'Windows Security'
- $cred = Get-UiaListItem -Class 'UserTile' -Name "CASTILLO.PAUL.B.1187395182's U.S. Government Signature Certificate"
- $cred[0].Mouse.LeftButtonClick()
- $okBtn = $winSecurity | Get-UiaButton -AutomationId 'SubmitButton' -Class 'CCPushButton' -Name 'OK' -Win32
- $okBtn.Invoke()
- Start-Sleep -m 70
- $activClient = Get-UiaWindow -Class '#32770' -Name 'ActivClient Login'
- if($activClient){
- $activClientInput = $activClient | Get-UiaEdit -AutomationId '3049' -Class 'Edit'
- $activClientInput.Value =""
- $activClientBtn = $activClient | Get-UiaButton -AutomationId '1' -Class 'Button' -Name 'OK' -Win32
- $activClientBtn.Invoke()
- }
- Start-Sleep -s 2
- $acceptWin = Get-UiaWindow -Class '#32770' -Name "Cisco AnyConnect | fshtx.ra.army.mil"
- $groupBtn = $acceptWin | Get-UiaButton -Class 'Button' -Name 'OK' -Win32
- $groupBtn.Invoke()
- Start-Sleep -s 2
- #accept
- $acceptWin = Get-UiaWindow -Class '#32770' -Name "Cisco AnyConnect"
- $acceptBtn = $acceptWin | Get-UiaButton -AutomationId '1' -Class 'Button' -Name 'Accept' -Win32
- $acceptBtn.Invoke()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement