VBS script sub routine to send e-mail

Needed something to send a e-mail from a VBS script when things were not going as planned, and thus came this sub. (If you plan to use this on a system with SMTP configured, then omit the configuration field lines)

 
Sub SendNotification (EmailFrom, EmailTo, EmailSubject, ErrorMessage, FileAttachment)
	Set Notify = CreateObject("CDO.Message")
 	With Notify
 		.From = EmailFrom
 		.To = EmailTo
 		.Subject = EmailSubject
 		.TextBody = ErrorMessage
 		.AddAttachment FileAttachment
 		.Configuration.Fields.Item _
 			("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
 		.Configuration.Fields.Item _
 			("http://schemas.microsoft.com/cdo/configuration/sendusing")="smtp.domain.com"
 		.Configuration.Fields.Item _
			("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 
		.Configuration.Fields.Update
 		.Send
 	End With
 	Set Notify = Nothing
End Sub

Just Change the smtp.domain.com to either the FQDN or IP of your mail server.

Here is an example of how to call the routine in your script:

 
  SendNotifcation _
"johndoe@domain.com", "janedoe@domain.com", "Error in Script", "Error In line 12", "c:\Logs.txt"

Setting Up Jumbo Frames on a VMware ESX Hosts

Jumbo Frames can be an important part of a IP Storage network, it reduces the overhead for a TCP/IP packet by increasing the MTU from 1500 to 9000 per packet. Now there are some strict requirements you need to follow to make this happen, or you will have MTU miss match errors that will actually slow down your storage network instead of speeding it up.

First Make sure you configure your SWITCH VLAN that will handle the traffic to use jumbo frames. For example on a HP Procurve from the configuration prompt:

vlan 30
jumbo

Second make sure that you configure a an interface on the Storage device that is also on this VLAN to use jumbo frames to communicate with your Host device. This depends on your storage vendor, but reading the documentation you should figure it out quickly.

Third configure all your host devices to communicate with your storage device via jumbo frames on the same vlan. Now I keep saying “same VLAN” for a very good reason, as you will quickly run into the dredded MTU missmatch errors if you try to route communications between VLANs. If you need to route to other devices or a device of a WAN that are not using jumbo frames then you must use a dedicated interface to communicate with the other device with MTU 1500. This interface does not have to be physical, on NetApp this can just be a VIF without -9000 configured on it.

Now that you have soem background on Jumbo frames here is how to enable them on a vSwitch on a VMware ESX host.

I created the VMware Networks port group on vSwitch2 called IPStorage before running the following CLI commands on the ESX host

First in the vCenter or Network Configuration add your vSwitch and setup a portgroup, in this example I used vSwitch2 and called the port group IPStorage. Once this is setup use put or login to the console of your ESX host.

Prep the vSwitch with the following command subsitute vSwitch2 with the vSwitch you wish to target

esxcfg-vswitch -m 9000 vSwitch2

now configure the portgroup as you named it earlier and assign it an IP at the same time

esxcfg-vmknic -a -i 10.10.2.10 -n 255.255.255.0 -m 9000 IPStorage

Finally test your configuration by trying to ping your storage interface with a jumbo frame packet:

vmkping -s 9000 10.10.2.101

If your ping fails make sure that your storage interface is correctly configured and on the same VLAN and subnet, also ensure that you have Jumbo Frames enabled the switch in the VLAN you are using. Also make sure that when you setup your portgroup in the VMware GUI that you input the VLAN number if you are using tagged vlans on the port.

Getting MS stuff to work on Ubuntu

This week my personal goal is to find ways to make Microsoft stuff work in Ubuntu. So here are a few projects I have noted and will try to post my progress.

Why is this compatibility so important?

For one, most people use Microsoft Windows, and in order to get more people to use Linux as an OS you have to find workarounds and ways to make the transition smoother, and to allow these new users of Linux to continue to work with their non-linux peers.

Second, if you are a developer you would like to know how to check your code and see what it looks like for your target audience, in this case I would recommend installing Virtual Box with a windows VM.

Some packages and projects that make this transition easier:

wine – This allows you to run some windows programs in windows

likewise open – allows you to join a windows domain with ease and if you want GPOs then look into likewise enterprise.

moonlight – open source port of Silverlight

The Mono Project – allows cross-platform compatibility of .Net framework

VLC Player – allows you to play multiple video audio file formats

Check out the https://help.ubuntu.com/community/Medibuntu

After completing the commands at the above link to enable the mediabuntu then install

sudo apt-get install gecko-mediaplayer

Final as a last resort use Virtual Box and create a windows VM on your ubuntu machine, you can even use seemless mode to make it look like the widows apps are on your ubuntu desktop.

Creating your own subversion edge server

Subversion Edge is pretty easy to use, just download the version you want (even loads in windows).

Here I’m just going to list some things to do to get your Ubuntu server off the ground. Download the Subversion from

http://www.open.collab.net/go/csvne2_r2a/

and copy the correct version to a directory on your Ubuntu Server.

Install java-jre – Follow this guide:

How to Install Java Runtime Environment (JRE) in Ubuntu

Install Subversion edge – Follow this Guide:
http://help.collab.net/topic/csvn/action/installcsvnonlinux.html

To install and not just run you will need to edit your sudoers file to pass the JAVA_HOME variable, see my previous post.

Then run bin/csvn install instead of start.

You can then update the newly installed configuration as need.

At this point you should be able to connect to your subversion server console and configure and maintain it from http://host:3343/csvn

enjoy

Changing Static DNS Search List Using a VBS login Script

This script is fuctional, but rare occurance of no DNS servers has happen when either the delete takes longer then expected or something happens at login that inerupts the completion of the login script. This is why I added a pre-check to see if the change is even needed in the first place.

The only Values needed to be changed are arrNewDNSServerSearchOrder which is the list of new DNS server you wish to add, strOneOfTheOldDNSServers which is a common DNS server already used that you may wish to change or add to, and strOneOfTheNewDNSServers which is one of the new DNS servers you plan to add so the script does not need to fully run at every login (only when change is needed).

If there are any ideas for fixing the rare “No DNS issue” or a better way to do this in PowerShell, please comment. Otherwise enjoy.

'==============================================================
'Script to update DNS settings (Such as adding more then one DNS server to the targeted NIC)
'
'By Paul - https://networksavy.wordpress.com
'Date: 08/23/2010
'==============================================================

'====================================================
'New List of DNS Servers to Apply
'====================================================
arrNewDNSServerSearchOrder = Array( "192.168.1.2", _
                                    "192.168.2.2", _
                                    "192.168.3.2"  )
                                    
'to find the right adapter(s) to change:
' This is the value that checks the right nic (A common DNS server that is already used)
strOneOfTheOldDNSServers = "192.168.2.19"
' This is to check if a value is already correct (So the replacement does not run again if not needed)
strOneOfTheNewDNSServers = "192.168.1.19"


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colNetCards = objWMIService.ExecQuery _
    ("Select DNSServerSearchOrder From Win32_NetworkAdapterConfiguration")

'============================================
'
' Test if the script even needs to be applied
' If the new DNS server exists then the script quits
'
'============================================
For Each objNetCard in colNetCards
  blnFound = 0
  arrDNSServerSearchOrder = objNetCard.DNSServerSearchOrder
  	If Not IsNull(arrDNSServerSearchOrder) Then
    	For i = 0 to UBound(arrDNSServerSearchOrder)
      		If (arrDNSServerSearchOrder(i) = strOneOfTheNewDNSServers) Then
				WScript.Quit
        Exit For
      End If
    Next    
  End If
Next

'============================================
'
' Replaces DNS Servers with new servers
'
'============================================
For Each objNetCard in colNetCards
  blnFound = 0
  arrDNSServerSearchOrder = objNetCard.DNSServerSearchOrder
  If Not IsNull(arrDNSServerSearchOrder) Then
    For i = 0 to UBound(arrDNSServerSearchOrder)
      If (arrDNSServerSearchOrder(i) = strOneOfTheOldDNSServers) Then
        arrDNSServerSearchOrder = Array()
        objNetCard.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
        wscript.sleep 600
        arrDNSServerSearchOrder = arrNewDNSServerSearchOrder
        objNetCard.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
        Exit For
      End If
    Next    
  End If
Next

WScript.Quit

Testing your Exchange Server Using Telnet

Very usefull, when testing SMTP connectivity, found that it still works with Exchange 2007.

Windows Vista/7 you need to install Telnet, or use putty

telnet ExchangeServer 25

Then Enter this command

helo DomainName<ENTER>

Response

205 OK

Enter the following

mail from: YourSourceEmail@domain.com<ENTER>

Response

250 OK - mail from YourSourceEmail@domain.com

Enter the following

rcpt to: RecipientEmail@domain.com<ENTER>

Response should be the following:

250 OK - Recipient RecipientEmail@domain.com

Enter the following:

data <ENTER>

response

354 Send data.  End with CRLF.CRLF

Enter the following

To: <recipient's display name><enter>
From: <your display name><enter>
Subject: <Subject field of Email message><enter>
<Enter you body text><enter><enter> . <enter>

Response

250 OK

at this point an e-mail should be sent you your destination address.

VBS Script based on date

Now this may be a little out there for some people but I created a VBS logon script that would popup a website based on the current date on the computer. Now keep in mind the trick is the format of the date.

'########################
' SCHEDULEDPOPUPS.vbs
' Scheduled URL Message Popups
' Author: Paul - https://networksavy.wordpress.com
' Date Created: 8/17/2010
' Used to Schedule System Wide Popup Messages at login
'#########################
' PopUpBetween (STARTDate,ENDDATE,POPUPURL,WIDTH,HEIGHT,fromLEFT,fromTOP)           Popup between these dates
'
' Date format is #YYYY-MM-DD#
'
'Example:
'PopUpBetween #2010-08-02#, #2010-08-04#, 470, 410, 300, 250, "http://www.google.com"
'This launches google between dates 8/2/2010 and 8/4/2010
'
'On Error Resume Next
'===================================================
' Scheduled Popups  Enter Schedule here One per line
'===================================================
'            |  START   |  |   END    |  W  |  H |  L |  T |  URL for popup
PopUpBetween #2010-08-02#, #2010-08-04#, 470, 410, 300, 250, "http://www.google.com"
'            |  START   |  |   END    |  W  |  H |  L |  T |  URL for popup

'-------------------------------------------------------------------
'  Sub for popups Between Two Dates, Date format is #YYYY-MM-DD#
'-------------------------------------------------------------------
Sub PopUpBetween (STARTDate,ENDDATE,WIDTH,HEIGHT,fromLEFT,fromTOP,POPUPURL)
	If (Date + 1) > STARTDATE And (Date - 1) < ENDDATE Then ' Ensures that the current date falls within the start and end date
		InternetExplorer POPUPURL,WIDTH,HEIGHT,fromLEFT,fromTOP ' Executes POPUPURL using the InternetExplorer Sub                                                          
	End If
End Sub

'----------------------------------------
' Sub for Internet Explorer
'----------------------------------------

Sub InternetExplorer (POPUPURL,WIDTH,HEIGHT,fromLEFT,fromTOP)
	With WScript.CreateObject ("InternetExplorer.Application")        'Start Internet Explorer
	  .Navigate POPUPURL                                '<------------ Navigate IE to a URL
      .fullscreen = 0                                   '<------------ Toggle Fullscreen mode 0=off 1=on
      .left       = fromLEFT                            '<------------ Possition from the left of screen
      .top        = fromTOP                             '<------------ Possition from the top of screen
      .Width      = WIDTH                               '<------------ Width of IE window
      .Height     = HEIGHT                              '<------------ Height of IE window
      .ToolBar    = 0                                   '<------------ Toggle IE Toolbar 0=off 1=on
      .MenuBar    = 0                                   '<------------ Toggle IE Menubar 0=off 1=on
      .StatusBar  = 0                                   '<------------ Toggle IE Statusbar 0=off 1=on
      .StatusText = ""                                  '<------------ Set status text in the status bar
      .Visible    = 1                                   '<------------ Toggle IE Statusbar 0=off 1=on
 	End With
End Sub

Now one could take this logic and use it with other tasks.

Windows Computer Power Configurations GPO

This one seems to be a moving target for most so I’ll post a Microsft KB for XP and some additional info for 2008 domains:

Windows XP – The meat and potatos of this KB is to give permissions to two registery keys to your users so your login scrip with work. If you take a look at the key in regedit you may get your own ideas on how to fix them, but just be careful and make backups and test your settings.

http://support.microsoft.com/kb/915160

 Windows XP/Vista/7 On 2008 Domains – the easy GPO setting

There is a new section of the GPO introduced in 2008 Domains when managing with a Vista or Windows 7 machine called Preferences, Control Panel Settings, here you will find it even easier to manage those pesky power settings and even configure new custom ones if you would like, and of course set which one is active.

Java Web Apps and Squid Proxy

Many Java Applications have a hard time authenticating with a Squid Proxy server, especially when using Kerberos. There is a handy work around for this.

Add these lines in you Squid.conf

acl Java browser Java/1.4 Java/1.5 Java/1.6
http_access allow localnet Java

Remember order matters with your http_access allow lines, so you should place this just above the http_access allow line that forces authentication. As an added mesure I add localnet ACL which can be set to you local network.