Everybody Staze...

Nobody leavz...

  • Home
  • About Me
    • LinkedIn
    • Lab
  • Contact
  • Links
  • Reviews
  • Sitemap
  • Weather

Scripting Cisco AnyConnect through powershell

2014/12/11 By staze

anyconnectThis is my first post on Powershell. Hopefully it won’t be too painful. Anyway, Campus recently mandated that we get away from the Cisco IPSec client, and move to the AnyConnect client. Problem is, the IPSec client was REALLY easy to put the username and password in the launch shortcut (just switches), and it’d connect. That doesn’t seem to be the case with the AnyConnect client, so I had to figure out how to do this in powershell. The script below (the fold) does this, and seems to work quite well. The reason for automating it is because we’re an almost 100% Mac shop, and there is a piece of “Banner” that is PC only. So we provide a Terminal Services/RDC Server that Mac users connect to, VPN fires up, and they’re able to connect to this package ((Note, our VPN admin had to allow VPN connections from a Multiuser environment, and Remote Desktop Connection)).

I just dropped this script into C:\powershell\vpn.ps1, and then created a shortcut in the user account start menu, startup, and had the path be: “%windir%\system32\windowspowershell\v1.0\powershell.exe C:\powershell\vpn.ps1” ((this is windows server 2003, sadly)).

Good luck. And thanks to the forums here, and it’s users, for the base code that I modified to work with my environment.

#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.example.com”
[string]$Login = “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}”)

#Start vpnui
start-Process -FilePath $vpnuiAbsolutePath

Filed Under: Coding Tagged With: Cisco AnyConnect, Powershell, Terminal Services, Windows Server 2003

The Hunger Games: Mockingjay – Part 1

2014/11/28 By staze

MockingjaySince I have previously reviewed both of the first two movies, I feel compelled to review the third movie, even though it’s part one of two. It will be a short review, however.

The movie takes off from pretty much the same moment Catching Fire left off, and we start to see District 13, and as those that have read the book know, it quickly becomes Katniss throwing a fit that Peeta wasn’t gotten out when the dome collapsed. It’s extremely sad everytime you see Plutarch Heavensbee (Philip Seymour Hoffman). Hopefully they won’t CG him into the second part of Mockingjay.

The movie stays relatively true to the book, and even includes a nicely done monologue of information that should have been in the earlier books: Why President Snow wears and smells of Roses.

All and All, I enjoyed the movie, and don’t want to give up too much incase people haven’t seen it, or read the book.

[xrr rating =4/5]

Filed Under: Reviews Tagged With: Catching Fire, Mockingjay Part 1, The Hunger Games

Arctic MX-4

2014/11/27 By staze

mx4_4g_g00_2I have a couple old Mac Pros sitting in the corner of my work office crunching numbers, and rendering randomly. Their CPU’s are always at 100%. I’ve had them apart half a dozen times to do upgrades, and I’ve never been very happy with the CPU temps. I’ve traditionally used Arctic Silver 5 (AS5) since it’s what I have a large tube of, and generally like. But, as I said, I’ve never liked the temp the Mac Pros run at, and because they’re at 100% all the time, the AS5 never has a real chance to “break in” (which requires many many hours of several thermal cycles). So, last week, I bought a tube of Arctic MX-4 (to be clear, Arctic Cooling (MX-4) is not the same company as Arctic Silver (AS5). The biggest advantage of the MX-4 being it has no break-in period.

Because the Mac Pros have Xeon 5300’s in them, I used the instructions on the Arctic Silver site for a “Horizontal Line“. After tinting the heat sink and heat spreader, I applied the compound and remounted the heat sinks. On power up, and after the machine had a chance to warm up, I am getting 42C and 44C on the two heat sinks at 100% load after 24 hours. On the Mac Pro I haven’t re-done yet, by contrast, I’m getting 44C and 50C. Mind you, those numbers are on a machine that I’ve never put a lot of effort into “breaking in”.

Of interest, I did notice that some of the AS5 on the machine I did looked like it had “broken down”. It was brownish, and had slumped quite a bit. Could be the AS5 I have is too old, or that because it never got a break-in period, it never settled into position, I really don’t know, but it was pretty gross to clean off the CPU heat spreader.

So, I’m happy, and hopefully those numbers will continue to hold. I will be re-doing the second Mac Pro next week. We’ll have to see if the same numbers show on that machine. Will definitely post those results as an update.

Filed Under: Reviews Tagged With: Arctic MX-4, Arctic Silver 5, Mac Pro

« Previous Page
Next Page »

Weather

Categories / Archives

  • Apple
  • Coding
  • Electronics
  • Energy
  • Home Ownership
  • Miscellany
  • Politics
  • Prius
  • Sys Admin
  • Travel
  • Uncategorized
  • Work
  • June 2026
  • April 2026
  • August 2025
  • April 2025
  • January 2024
  • February 2021
  • July 2020
  • January 2020
  • April 2019
  • March 2018
  • February 2018
  • June 2017

Copyright © 2026 · Staze On Genesis Framework · WordPress · Log in