<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JJClements.co.uk &#187; Scripting</title>
	<atom:link href="http://www.jjclements.co.uk/index.php/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jjclements.co.uk</link>
	<description>Clem&#039;s Technical Blog</description>
	<lastBuildDate>Tue, 08 Jun 2010 22:26:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>KiXtart script to shrink VMDK for smaller VCB backups</title>
		<link>http://www.jjclements.co.uk/2010/04/13/kixtart-script-to-shrink-vmdk-for-smaller-vcb-backups/</link>
		<comments>http://www.jjclements.co.uk/2010/04/13/kixtart-script-to-shrink-vmdk-for-smaller-vcb-backups/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 17:00:30 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[VCB]]></category>
		<category><![CDATA[VMDK]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=738</guid>
		<description><![CDATA[When I first started using VMware ESX I was testing VMware Consolidated Backup (VCB) to dump my virtual machines to a staging area before being copied offsite. I noticed that one of the VMs had a VMDK attached that as far as the OS (Windows Server 2003) was concerned with had all of the data [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started using VMware ESX I was testing VMware Consolidated Backup (VCB) to dump my virtual machines to a staging area before being copied offsite. I noticed that one of the VMs had a VMDK attached that as far as the OS (Windows Server 2003) was concerned with had all of the data deleted on that volume. After initiating a VCB dump (backup) on the VM I noticed that the VMDK that was dumped to my staging area strangely appeared to contain data. The VMDK size was considerably larger than it should have been for a disk that Windows reported as containing zero data.</p>
<p><span id="more-738"></span></p>
<p>After some investigation I realised that when VCB performed a dump of the VMDK it was correctly dumping the used space. It then dawned on me that when Windows was deleting files from the disk it was actually only deleting the 'pointer' to the data and not the data itself. When VCB was dumping the VMDK it was correctly dumping all blocks of the disk that contained data. I then started looking for a way to clean blocks that were no longer being used but still contained remnants from deleted files. I found a tool called <a rel="nofollow" href="http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx" target="_blank">SDelete</a> that writes zero's where the disk contains free space as seen by the Operating System.</p>
<p>I incorporated SDelete into a basic script that also uses Defrag (the Windows utility for defragmenting disks) to tidy up volumes and potentially reduce the size of backups when using VCB.</p>
<p>The script first enumerates all local drives on the VM. For each drive that Windows deems as being a local disk the script then defragments the volume and uses SDelete to zero any free space that the disk may have. The script is written in <a rel="nofollow" href="http://www.kixtart.org" target="_blank">KiXtart</a>.</p>
<p>Here is the script:</p>
<p>;=====================================================<br />
;=====================================================<br />
;<br />
; ENUMERATE LOCAL DRIVES - DEFRAG &#038; ZERO EMPTY BLOCKS<br />
;<br />
;=====================================================<br />
;=====================================================</p>
<p>;=====================Accept EULA=====================<br />
WriteValue("HKCU\Software\Sysinternals\SDelete", "EulaAccepted", "1", "REG_DWORD")</p>
<p>$Drives = GetObject("winmgmts:").ExecQuery("select Name,DriveType from Win32_LogicalDisk")</p>
<p>For Each $Drive in $Drives</p>
<p>		If $Drive.DriveType = 3</p>
<p>			SHELL "%comspec% /c " + chr(34) + "defrag.exe " + $Drive.name + " -f" + chr(34)<br />
			SHELL "%comspec% /c " + chr(34) + "sdelete.exe -c " + $Drive.name + chr(34)</p>
<p>		EndIf</p>
<p>Next</p>
<p>;=====================================================</p>
<p>I use this by placing the folder CleanDisk (download link below) in<strong> C:\Program Files</strong>. I create a Windows scheduled task to run either KIX32.exe or WKIX32.exe on say a monthly basis.</p>
<p>NOTE: If you have multiple VMs with VMDKs residing on the same physical storage you will probably want to consider staggering the schedules to reduce I/O on the physical disks.</p>
<p>Download the script and necessary files - <a rel="nofollow" href="http://www.jjclements.co.uk/wp-content/uploads/2010/04/cleandisk.zip" target="_blank">HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2010/04/13/kixtart-script-to-shrink-vmdk-for-smaller-vcb-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiXtart script to enable Outlook Anywhere or RPC-HTTPS</title>
		<link>http://www.jjclements.co.uk/2009/08/07/kixtart-script-to-enable-outlook-anywhere-or-rpc-https/</link>
		<comments>http://www.jjclements.co.uk/2009/08/07/kixtart-script-to-enable-outlook-anywhere-or-rpc-https/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 16:43:27 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Office]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[outlook anywhere]]></category>
		<category><![CDATA[rpc-https]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=306</guid>
		<description><![CDATA[At work, people were using VPN to access their email out of the office, but I have always thought that logging into a corporate network via VPN for most users is an extra hassle that they could probably do without. I had considered setting up RPC over HTTPS for Exchange 2003 but during a meeting [...]]]></description>
			<content:encoded><![CDATA[<p>At work, people were using VPN to access their email out of the office, but I have always thought that logging into a corporate network via VPN for most users is an extra hassle that they could probably do without. I had considered setting up RPC over HTTPS for Exchange 2003 but during a meeting regarding disaster recovery it became evident it was actually now a necessity. So, after configuring the server for RPC-HTTPS I had the small problem of deploying the settings to Outlook clients en masse.</p>
<p><span id="more-306"></span></p>
<p>I had already used a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> logon script to configure 'Cached Mode' for my Outlook 2003/7 clients by modifying some HKCU registry keys for users - <a href="http://www.jjclements.co.uk/index.php/2008/08/21/regkey-to-enable-disable-outlook-2003-cached-mode/" target="_blank" rel="nofollow">Regkey to enable &#038; disable Outlook 2003 cached mode</a>.</p>
<p>After setting up an Outlook client in VMware Workstation I configured RPC-HTTPS and exported the regkey from the post above (see below for the key.) A fresh install of Outlook with a clean profile and the above key imported revealed that the settings for RPC-HTTPS are stored in the same place as those in the post for enabling cached mode. A combination of changing the values in Outlook and using <a href="http://technet.microsoft.com/en-us/sysinternals/bb896652.aspx" target="_blank" rel="nofollow">Regmon</a> allowed me to narrow down exactly what each registry value is used for and the data that each value needs to contain (the data for each registry value is stored as type REG_BINARY which as hexadecimal is unreadable.)</p>
<p>Here is an outline of the registry key and each value with my own description:</p>
<p>HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\(profilename)\13dbb0c8aa05101a9bb000aa002fc45a</p>
<p>00036623 = Enables 'Connect to Microsoft Exchange using HTTP' as well as 'On fast/slow networks...'<br />
00036627 = Sets the proxy server authentication type (data: 01000000 -> Basic, 02000000 -> NTLM)<br />
001f6622 = Sets the 'proxy server for Exchange' (https://) text box<br />
001f6625 = Sets the 'this principle name' text box</p>
<p>One other registry key I had to set (as per <a href="http://support.microsoft.com/kb/820281" target="_blank" rel="nofollow">KB820281</a>) to stop clients being prompted for a username/password was:</p>
<p>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa</p>
<p>lmcompatibilitylevel = 3</p>
<p>I amended my <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> login script as follows with the new registry keys, values and their data. The next time users logged on they were connected using RPC over HTTPS:</p>
<p>WRITEVALUE("HKLM\SYSTEM\CurrentControlSet\Control\Lsa", "lmcompatibilitylevel", "3", "REG_DWORD")<br />
WRITEVALUE("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a", "00036623", "2b000000", "REG_BINARY")<br />
WRITEVALUE("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a", "00036627", "02000000", "REG_BINARY")<br />
WRITEVALUE("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a", "001f6622", "xxxx", "REG_BINARY")<br />
WRITEVALUE("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a", "001f6625", "xxxx", "REG_BINARY")</p>
<p>You can verify that users are connected using RPC over HTTPS by holding down CTRL and SHIFT on the keyboard and using the mouse to right-click the system tray icon. Click on the 'Connection Status...' option and you will see that the 'Conn' column displays multiple connections of type: HTTPS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2009/08/07/kixtart-script-to-enable-outlook-anywhere-or-rpc-https/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>KiXtart script to generate and email uptime report</title>
		<link>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/</link>
		<comments>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 11:05:26 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows Server 2003]]></category>
		<category><![CDATA[uptime]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=178</guid>
		<description><![CDATA[As part of my Service Level Agreement at work I have to produce a monthly uptime report for each server. Rather than generate individual reports for each server I decided to write a KiXtart script that would generate a report for all servers and email it to me each month. The following script uses two [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my Service Level Agreement at work I have to produce a monthly uptime report for each server. Rather than generate individual reports for each server I decided to write a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script that would generate a report for all servers and email it to me each month.</p>
<p><span id="more-178"></span></p>
<p>The following script uses two other applications:</p>
<p><a href="http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm" target="_blank" rel="nofollow">BMail</a> - A command line SMTP mailing tool<br />
<a href="http://support.microsoft.com/kb/232243" target="_blank" rel="nofollow">Uptime</a> - Allows you to estimate Server availability</p>
<p>Full credit to Craig Peacock for BMail.</p>
<p>Here is the script:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Clear Existing Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>IF EXIST ("Report")<br />
DEL "Report\*.txt"<br />
ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Produce Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>;Convert YYYY/MM/DD to DD-MM-YYYY<br />
$temp = @DATE<br />
$todaysdate = SUBSTR($temp, 9, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 6, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 1, 4)</p>
<p>;Array containing server names<br />
Dim $ComputerNames[5]<br />
$ComputerNames[0] = "Server01"<br />
$ComputerNames[1] = "Server02"<br />
$ComputerNames[2] = "Server03"<br />
$ComputerNames[3] = "Server04"<br />
$ComputerNames[4] = "Server05"</p>
<p>;If Report directory doesn't exist then create it<br />
IF NOT EXIST ("Report")<br />
MD "Report"<br />
ENDIF</p>
<p>;Output uptime report for all computers in the array<br />
For Each $Element In $ComputerNames</p>
<p>IF $Element = ""<br />
GoTo "Email"<br />
ENDIF</p>
<p>shell "%comspec% /c " + chr(34) + "Uptime.exe" + " " + $Element + " " + chr(34) + " /s /p:31 >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"</p>
<p>Next</p>
<p>:Email<br />
;===============================================<br />
;===============================================<br />
;<br />
;         Email Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$emailserver = "someemailserver"<br />
$toaddress = "james" + chr(64) + "somedomain.com"<br />
$fromaddress = "uptime" + chr(64) + "somedomain.com"<br />
$subject = "Uptime Report For all London Servers"</p>
<p>;Form email command<br />
$emailcommand = "bmail -s " + $emailserver + " -t " + $toaddress + " -f " + $fromaddress + " -h -a " + chr(34) + $subject + chr(34) + " -m " + "Report\" + $todaysdate + "-UptimeReport.txt" + " -c"</p>
<p>RUN ($emailcommand)</p>
<p>;===============================================</p>
<p>The script works by generating a file that contains the results of uptime.exe for each server specified. The contents of the file are then emailed using bmail.</p>
<p>This script obviously requires a few variables to be modified to get it to work in another environment. The following will need to be altered:</p>
<p>Dim $ComputerNames[5] - you will need to change the numeric value to the number of servers you want to generate a report for</p>
<p>NOTE: the example above is for 5 servers. If you wanted to monitor 4 servers then you will need to modify the array to change the number of elements to 4. So your array would look like (the last line has been removed):</p>
<p>$ComputerNames[0] = "Server01"<br />
$ComputerNames[1] = "Server02"<br />
$ComputerNames[2] = "Server03"<br />
$ComputerNames[3] = "Server04"</p>
<p>$ComputerNames[0] = "Server01" - you need to change Server01 to the server you want to generate a report for<br />
$emailserver - the name of your email server (the server running this script must be allowed to relay through it)<br />
$toaddress - the address you want the email alert to go to<br />
$fromaddress - the (spoof) address you want the email to appear to come from<br />
$subject - the subject line of the email</p>
<p>I use a scheduled task on a Windows Server 2003 to run this script once a month. It generates a report for the last 31 days of uptime for each server in the array and then emails me the report.</p>
<p>NOTE: you can change 31 day period that the script gathers uptime information for by modifying /p:31 on the following line:</p>
<p>(31 represents the number of days in the past to gather uptime statistics for)</p>
<p>shell "%comspec% /c " + chr(34) + "Uptime.exe" + " " + $Element + " " + chr(34) + " /s /p:31 >> Report\$todaysdate-UptimeReport.txt"</p>
<p>To use this:</p>
<p>1) Save the above script as kixtart.kix in a directory containing the kixtart application<br />
2) Save bmail.exe and uptime.exe (available from the links above) in the same directory<br />
3) Modify variables as appropriate<br />
4) Make sure that the server running the script can relay email through your email server<br />
5) Test by running the script manually and/or create the scheduled task</p>
<p>Alternatively, download the above script and necessary files - <a href="http://www.jjclements.co.uk/wp-content/uploads/2009/03/uptime-report.zip" target="_blank" rel="nofollow">HERE</a></p>
<p>The end result is an email with a breakdown of uptime availability for each server including any dates and times where necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiXtart script to check for website availability</title>
		<link>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/</link>
		<comments>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 12:06:42 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows Server 2003]]></category>
		<category><![CDATA[SLA]]></category>
		<category><![CDATA[uptime]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=130</guid>
		<description><![CDATA[At work there is an old web application that is managed offsite by a hosting company. It runs on Oracle 9iAS. Apparently there is an issue with Oracle 9i and the web service will frequently crash (due to a known caching problem) taking the application offline. Rather than spending money on the software and licensing [...]]]></description>
			<content:encoded><![CDATA[<p>At work there is an old web application that is managed offsite by a hosting company. It runs on Oracle 9iAS. Apparently there is an issue with Oracle 9i and the web service will frequently crash (due to a known caching problem) taking the application offline.</p>
<p><span id="more-130"></span></p>
<p>Rather than spending money on the software and licensing required to upgrade both Oracle and the Operating System (as it's being replaced anyway) the company made a decision to live with the issue for the time being. I decided to write a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script to monitor the website and let me know of any issues it may incur.</p>
<p>The following script uses two other applications:</p>
<p><a href="http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm" target="_blank" rel="nofollow">BMail</a> - A command line SMTP mailing tool<br />
<a href="http://johnmu.com/web-toolbox-1/" target="_blank" rel="nofollow">WebResult</a> - A command line URL result code tool</p>
<p>Full credit to Craig Peacock for BMail and John Mueller for WebResult.</p>
<p>Here is the script:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Remove temp files<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>IF EXIST ("result.txt")<br />
DEL ("result.txt")<br />
ENDIF</p>
<p>IF EXIST ("status.txt")<br />
DEL ("status.txt")<br />
ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Check/record http status in result.txt<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$website = "http://www.jjclements.co.uk"</p>
<p>SHELL "%comspec% /c " + chr(34) + "webresult.exe " + $website + chr(34) + " >> result.txt"</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Open result.txt and read into variable<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>getfilecontents("result.txt")</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Explode variable into array<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$myarray = SPLIT ($result, "	", -1)</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Declare global variable to store desc<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$errordesc = ""</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Check each array element against codes<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$element = $myarray[1]<br />
 SELECT</p>
<p>  CASE $element = "0"<br />
  $errordesc = "The current status is: Error " + $element + " - Website Unavailable"</p>
<p>  CASE $element = "400"<br />
  $errordesc = "The current status is: Error " + $element + " - Bad Request"</p>
<p>  CASE $element = "403"<br />
  $errordesc = "The current status is: Error " + $element + " - Forbidden"</p>
<p>  CASE $element = "404"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Found"</p>
<p>  CASE $element = "405"<br />
  $errordesc = "The current status is: Error " + $element + " - Method Not Allowed"</p>
<p>  CASE $element = "406"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Acceptable"</p>
<p>  CASE $element = "408"<br />
  $errordesc = "The current status is: Error " + $element + " - Request Timeout"</p>
<p>  CASE $element = "409"<br />
  $errordesc = "The current status is: Error " + $element + " - Conflict"</p>
<p>  CASE $element = "410"<br />
  $errordesc = "The current status is: Error " + $element + " - Gone"</p>
<p>  CASE $element = "500"<br />
  $errordesc = "The current status is: Error " + $element + " - Internal Server Error"</p>
<p>  CASE $element = "501"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Implemented"</p>
<p>  CASE $element = "502"<br />
  $errordesc = "The current status is: Error " + $element + " - Bad Gateway"</p>
<p>  CASE $element = "503"<br />
  $errordesc = "The current status is: Error " + $element + " - Internal Server Error"</p>
<p>  CASE $element = "504"<br />
  $errordesc = "The current status is: Error " + $element + " - Gateway Timeout"</p>
<p>  CASE $element = "505"<br />
  $errordesc = "The current status is: Error " + $element + " - HTTP Version not supported"</p>
<p>  CASE 1<br />
  EXIT</p>
<p> ENDSELECT</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Threshold - Times to retry + interval<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$numberofretries = "2"<br />
$latencyseconds = "10"</p>
<p>IF $numberofretries > "0"</p>
<p>DO</p>
<p>SLEEP $latencyseconds</p>
<p>IF EXIST ("result.txt")<br />
DEL ("result.txt")<br />
ENDIF</p>
<p>SHELL "%comspec% /c " + chr(34) + "webresult.exe " + $website + chr(34) + " >> result.txt"</p>
<p>getfilecontents("result.txt")</p>
<p>$mytemparray = SPLIT ($result, "	", -1)</p>
<p>$tempelement = $mytemparray[1]</p>
<p>IF NOT $element = $tempelement<br />
EXIT<br />
ENDIF</p>
<p>$currentretry = $currentretry + 1</p>
<p>UNTIL $numberofretries = $currentretry</p>
<p>ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Email Server Status<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$emailserver = "someemailserver"<br />
$toaddress = "james" + chr(64) + "somedomain.com"<br />
$fromaddress = "serverfailure" + chr(64) + "somedomain.com"<br />
$subject = "Server Issue"</p>
<p>;Form email body<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo WebServer is currently offline >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo " + $errordesc + " >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo Please restart the WebServer application to ensure SLAs are adhered to! >> status.txt"</p>
<p>;Form email command<br />
$emailcommand = "bmail -s " + $emailserver + " -t " + $toaddress + " -f " + $fromaddress + " -h -a " + chr(34) + $subject + chr(34) + " -m " + "status.txt" + " -c"</p>
<p>SHELL ($emailcommand)</p>
<p>;=======================================<br />
;	Get File Contents<br />
;=======================================</p>
<p>Function getfilecontents($filesource)</p>
<p>OPEN (1, "$filesource")<br />
$result = READLINE (1)<br />
CLOSE (1)</p>
<p>EndFunction</p>
<p>;=======================================</p>
<p>This script obviously requires a few variables to be modified to get it to work in another environment. The following will need to be altered:</p>
<p>$website - you will need to enter your own website you want to monitor here (you must use http://)<br />
$numberofretries - the number of times the script will test the website before emailing an error<br />
$latencyseconds - the time in seconds before each retry (if $numberofretries is NOT set to 0)<br />
$emailserver - the name of your email server (the server running this script must be allowed to relay through it)<br />
$toaddress - the address you want the email alert to go to<br />
$fromaddress - the (spoof) address you want the email to appear to come from<br />
$subject - the subject line of the email</p>
<p>The only other thing you may want to change is the message contained within the email (underneath ';Form email body'). I have a few instances of this script monitoring different servers so I have customised the email body for each server to inform me of the server name and IP address etc.</p>
<p>As mentioned the script makes use of a threshold although it isn't used if you set $numberofretries = "0". The threshold sets the number of times to try the website before sending an email. You can also set the delay between each retry (in seconds) by setting a value for $latencyseconds.</p>
<p>I use a scheduled task on a Windows Server 2003 to run this script every 5 minutes. When there is a problem with the web application I am alerted to it and can respond as necessary. One thing to be aware of, if you set your scheduled task to run every 5 minutes but you set the script to retry say 3 times with a latency of 120 seconds (total 360 seconds - 6 minutes) then the scheduled task will try to run again before the script has finished causing problems.</p>
<p>To use this: </p>
<p>1) Save the above script as kixtart.kix in a directory containing the kixtart application<br />
2) Save webresult.exe and bmail.exe (available from the links above) in the same directory<br />
3) Modify variables as appropriate<br />
4) Make sure that the server running the script can relay email through your email server<br />
5) Test by running the script manually and/or create the scheduled task</p>
<p>Alternatively, download the above script and necessary files - <a href="http://www.jjclements.co.uk/wp-content/uploads/2009/02/website-availability-script.zip" target="_blank" rel="nofollow">HERE</a></p>
<p>The end result is an email that tells you the exact http error code and description when your web application becomes unavailable and meets any threshold that may be set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regkey to disable XP dial-up connection logon</title>
		<link>http://www.jjclements.co.uk/2008/08/22/regkey-to-disable-xp-dial-up-connection-logon/</link>
		<comments>http://www.jjclements.co.uk/2008/08/22/regkey-to-disable-xp-dial-up-connection-logon/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 11:34:47 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Registry]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[dun]]></category>
		<category><![CDATA[logon]]></category>
		<category><![CDATA[msgina]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=74</guid>
		<description><![CDATA[Here is a registry key I run from a startup script to disable the option that allows users to invoke a "Log on using dial-up connection". Having had experience of working in a school I know how kids will use any excuse to distract them from logging onto a computer and starting the lesson! Here [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a registry key I run from a startup script to disable the option that allows users to invoke a "Log on using dial-up connection". Having had experience of working in a school I know how kids will use any excuse to distract them from logging onto a computer and starting the lesson!</p>
<p><span id="more-74"></span></p>
<p>Here is the logon screen before the registry key has been added:</p>
<p><img src="http://www.jjclements.co.uk/wp-content/uploads/2008/08/beforedunregkey.png" alt="beforedunregkey.png" /></p>
<p>Here is what happens if a user selects the "Log on using dial-up connection" checkbox before logging on:</p>
<p><img src="http://www.jjclements.co.uk/wp-content/uploads/2008/08/duringdunlogon.png" alt="duringdunlogon.png" /></p>
<p>Setting the following registry key will disable the checkbox, disabling all users from using the dial-up connection feature:</p>
<p>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon</p>
<p>you will need to manually create a new string value (REG_SZ) called RasDisable. Set the value's data to 1.</p>
<p>Here is the final result:</p>
<p><img src="http://www.jjclements.co.uk/wp-content/uploads/2008/08/afterdunregkey.png" alt="afterdunregkey.png" /></p>
<p>And finally here is what I wrote to add the regkey to all computers using a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> startup script through Group Policy:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;       DISABLE LOGON USING DIAL-UP CONNECTION<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>IF READVALUE("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "RasDisable") <>"1"<br />
	WRITEVALUE("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "RasDisable", "1", "REG_SZ")<br />
ENDIF</p>
<p>NOTE: I've noticed that the quote marks are not displayed properly on this page. Here is the <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script in its intended form:</p>
<p><a href="http://www.jjclements.co.uk/wp-content/uploads/2008/08/kixtart-disable-logon-dun.txt" target="_blank" rel="nofollow">Download Here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2008/08/22/regkey-to-disable-xp-dial-up-connection-logon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiXtart script to backup MSSQL database</title>
		<link>http://www.jjclements.co.uk/2008/08/22/kixtart-script-to-backup-mssql-database/</link>
		<comments>http://www.jjclements.co.uk/2008/08/22/kixtart-script-to-backup-mssql-database/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 09:41:57 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[backup]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=73</guid>
		<description><![CDATA[Here is another quick KiXtart script I wrote to backup a Microsoft SQL database on a server. I personally run it locally on the server that contains the database I want to backup using a scheduled task. It connects to the MSSQL database using the OSQL command line utility which it runs through a shell. [...]]]></description>
			<content:encoded><![CDATA[<p>Here is another quick <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script I wrote to backup a Microsoft SQL database on a server. I personally run it locally on the server that contains the database I want to backup using a scheduled task. It connects to the MSSQL database using the OSQL command line utility which it runs through a shell.</p>
<p><span id="more-73"></span></p>
<p>When you install MSSQL on a server, the ‘PATH’ environment variable is changed to include the location of the SQL tools (the default being: C:\Program Files\Microsoft SQL Server\80\Tools\BINN). The script runs without needing to know where osql.exe is installed and passes it switches to initiate a complete backup. Once the backup has completed SQL Server Enterprise Manager reflects the new date and time of the last backup taken as though you have used its own SQL Server Backup utility.</p>
<p>The script executes osql.exe with 2 switches, -E and -Q.</p>
<p>-E = Uses windows authentication (the credentials of the currently logged on user OR if using a scheduled task to run the script the credentials specified when initially creating the task)</p>
<p>-Q = Runs the SQL statement and exits osql.exe</p>
<p>Here is the script, you will only need to modify 2 variables ($databasename and $backuplocation) to set the name of the database you want to backup and the location of where you want the backup saved:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Backup MSSQL Database<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>;Convert YYYY/MM/DD to DD-MM-YYYY<br />
$temp = @DATE<br />
$todaysdate = SUBSTR($temp, 9, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 6, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 1, 4)</p>
<p>;Set Backup Parameters<br />
$databasename = "MyDatabase"<br />
$backuplocation = "c:\MSSQL Backups\"</p>
<p>;If backup directory doesn't exist then create it<br />
IF NOT EXIST ($backuplocation)<br />
MD ($backuplocation)<br />
ENDIF</p>
<p>;Delete existing backup if it exists<br />
IF EXIST ($backuplocation)<br />
DEL ($backuplocation + "*.*")<br />
ENDIF</p>
<p>;Form Backup command<br />
$backupcommand = "osql -E -Q " + chr(34) + "BACKUP DATABASE " + $databasename + " TO DISK = '" + $backuplocation + $databasename + "-" + $todaysdate + ".bak" + "'" + chr(34)</p>
<p>SHELL ($backupcommand)</p>
<p>;===============================================</p>
<p>If you ever wanted to restore from this backup you could use the command line to restore it again. Here is an example restore command (remove the brackets):</p>
<p>osql -E -Q "RESTORE DATABASE (databasename) FROM DISK = 'c:\MSSQL Backups\(mydatabasebackup.bak)'"</p>
<p>You can obviously also use SQL Server Enterprise Managers own SQL Server Backup utility to restore the database as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2008/08/22/kixtart-script-to-backup-mssql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiXtart script to retrieve Active Directory user info</title>
		<link>http://www.jjclements.co.uk/2008/08/21/kixtart-script-to-retrieve-active-directory-user-info/</link>
		<comments>http://www.jjclements.co.uk/2008/08/21/kixtart-script-to-retrieve-active-directory-user-info/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 16:18:05 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[logon]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=72</guid>
		<description><![CDATA[Here's a quick script written using KiXtart to retrieve information for a user (object) in Active Directory. Once enumerated, object information is stored in variables to be used later. The organisation I work for has an application that requires each user’s telephone extension. So I use this script to retrieve the user’s telephone extension (from [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a quick script written using <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> to retrieve information for a user (object) in Active Directory. Once enumerated, object information is stored in variables to be used later.</p>
<p><span id="more-72"></span></p>
<p>The organisation I work for has an application that requires each user’s telephone extension. So I use this script to retrieve the user’s telephone extension (from the Active Directory Telephone number attribute) during logon. It then writes that value to the appropriate registry key required by the application. This way all I have to remember to do when creating a new user or changing the users telephone is to set/change the 'Telephone number' attribute on the users account using the Active Directory Users and Computers MMC.</p>
<p>Here's the script:</p>
<p>;Retrieve Active Directory user information<br />
$objSysInfo = CreateObject("ADSystemInfo")<br />
$strUser = $objSysInfo.UserName<br />
$objUser = GetObject("LDAP://" + $strUser)</p>
<p>$strPhone = $objUser.telephoneNumber<br />
$strName = $objUser.FullName<br />
$strTitle = $objUser.Title<br />
$strMail = $objUser.mail<br />
$strDepartment = $objUser.Department<br />
$strCompany = $objUser.Company<br />
$strStreet = $objUser.StreetAddress<br />
$strPostalCode = $objUser.PostalCode<br />
$strCity = $objUser.L<br />
$strCountry = $objUser.Co<br />
$strPhone = $objUser.telephoneNumber<br />
$strFax = $objUser.FacsimileTelephoneNumber<br />
$strMobile = $objUser.Mobile<br />
$strWeb = $objUser.wWWHomePage</p>
<p>As an example, here is how I could now write an Active Directory attribute to the registry, checking for some form of its existence before hand:</p>
<p>IF NOT $strPhone = ""<br />
WRITEVALUE("HKCU\Software\MyTelephoneApp", "TelephoneNo", $strPhone, "REG_SZ")<br />
ENDIF</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2008/08/21/kixtart-script-to-retrieve-active-directory-user-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
