Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. Import-Module C:\Users\PAUL.CASTILLO3\Downloads\UIAutomation.0.8.7B3.NET40\UIAutomation.dll
  2. [UIAutomation.Preferences]::Highlight = $false
  3. [UIAutomation.Preferences]::Log = $false
  4. [UIAutomation.Preferences]::AutoLog = $false
  5. [UIAutomation.Preferences]::OnErrorScreenShot = $false
  6. $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
  7.  
  8. function Connect-VPN() {
  9. $vpnUI = Get-Process | Where-Object {$_.Name -like "vpnui"}
  10. if($vpnUI){
  11. Write-Host "Found VPN process" -ForegroundColor Yellow
  12. Retrieve-VPN
  13. } else {
  14. #Write-Host "Need to start Cisco Client"
  15. $vpn = Start-Process -FilePath "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
  16. Retrieve-VPN
  17. }
  18. }
  19.  
  20. function Disconnect-VPN(){
  21. $vpnUI = Get-Process | Where-Object {$_.Name -like "vpnui"}
  22. if($vpnUI){
  23. Write-Host "found it"
  24. $isVPNConnected = $true
  25.  
  26. $vpnWin = Get-UiaWindow -Class '#32770' -Name 'Cisco AnyConnect Secure Mobility Client'
  27. if($vpnWin){
  28. Set-ForegroundWindow $vpnWin.Current.NativeWindowHandle
  29. }
  30.  
  31. try {
  32. $vpnStart = $vpnWin | Get-UiaButton -Class 'Button' -Name 'Disconnect' -Win32
  33. } catch {
  34.  
  35. }
  36.  
  37. if($vpnStart) {
  38. $vpnStart.Invoke()
  39. Write-Host "Disconnected from VPN"
  40. } else {
  41. Write-Host "VPN is not connected."
  42. }
  43. }
  44. }
  45.  
  46. function Retrieve-VPN {
  47. $vpnWin = Get-UiaWindow -Class '#32770' -Name 'Cisco AnyConnect Secure Mobility Client'
  48. if($vpnWin){
  49. Set-ForegroundWindow $vpnWin.Current.NativeWindowHandle
  50. } else {
  51. Write-Host "unable to find VPN process"
  52. break
  53. }
  54. $vpnStart = $vpnWin | Get-UiaButton -Class 'Button' -Name 'Connect' -Win32
  55. $vpnStart.Invoke()
  56.  
  57. Start-Sleep -s 3
  58. $winSecurity = Get-UiaWindow -Class '#32770' -Name 'Windows Security'
  59. $cred = Get-UiaListItem -Class 'UserTile' -Name "CASTILLO.PAUL.B.1187395182's U.S. Government Signature Certificate"
  60. $cred[0].Mouse.LeftButtonClick()
  61.  
  62. $okBtn = $winSecurity | Get-UiaButton -AutomationId 'SubmitButton' -Class 'CCPushButton' -Name 'OK' -Win32
  63. $okBtn.Invoke()
  64.  
  65. Start-Sleep -m 70
  66. $activClient = Get-UiaWindow -Class '#32770' -Name 'ActivClient Login'
  67. if($activClient){
  68. $activClientInput = $activClient | Get-UiaEdit -AutomationId '3049' -Class 'Edit'
  69. $activClientInput.Value =""
  70. $activClientBtn = $activClient | Get-UiaButton -AutomationId '1' -Class 'Button' -Name 'OK' -Win32
  71. $activClientBtn.Invoke()
  72. }
  73. Start-Sleep -s 2
  74.  
  75. $acceptWin = Get-UiaWindow -Class '#32770' -Name "Cisco AnyConnect | fshtx.ra.army.mil"
  76. $groupBtn = $acceptWin | Get-UiaButton -Class 'Button' -Name 'OK' -Win32
  77. $groupBtn.Invoke()
  78. Start-Sleep -s 2
  79.  
  80. #accept
  81. $acceptWin = Get-UiaWindow -Class '#32770' -Name "Cisco AnyConnect"
  82. $acceptBtn = $acceptWin | Get-UiaButton -AutomationId '1' -Class 'Button' -Name 'Accept' -Win32
  83. $acceptBtn.Invoke()
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement