Using Powershell to access DB2


I have written a few blog posts recently related to DB2.  They are listed below:

Connecting to a DB2 database using C#

Powershell and DB2 Table Join

Automated DB2 Backup Script

A while back, I was experimenting with DB2 and trying to access DB2 using Powershell.  Having Googled around, there weren’t any real examples and the ones I did find, were kind of out-dated and mentioned needing a bunch of other components installed just to get the data access providers I need.  I never did figure out what all was required…

The script I initially used and experimented with is posted below; along with the error message.  I later posted this problem on  Stack Overflow and the error I was receiving, hoping to receive some guidance or insight into the problem.   If you’re not familiar with Stack Overflow, it is for programmers and other computer professionals that write code to post questions related to problems they are having, various tools they may be using, software algorithms, or practical questions to problems unique to the programming profession.  To date, my post has never answered.  I’ll probably answer it myself and include a link back to this article.   The Stack Overflow question is here.

The code I originally used was using the DB2OLEDB provider provider my Microsoft.    When trying to fill the DataSet, I kept receiving an exception error.  However, query results still worked.

Here is the code using DB2OLEDB provider:

   1:  $cn = new-object system.data.OleDb.OleDbConnection("Provider=DB2OLEDB;User ID=DB2ADMIN;Password=mypassword;Initial Catalog=SAMPLE;Network Transport Library=TCP;Host CCSID=37;PC Code Page=1252;Network Address=localhost;Network Port=50000;Package Collection=<collection>;Default Schema=<schema>;Process Binary as Character=False;Units of Work=RUW;DBMS Platform=DB2/NT;Defer Prepare=False;Persist Security Info=True;Connection Pooling=False;");
   2:   
   3:  $ds = new-object "System.Data.DataSet" "dsEmployee" 
   4:   
   5:  $q = "SELECT EMPNO"
   6:  $q = $q + ",FIRSTNME"
   7:  $q = $q + ",LASTNAME"
   8:  $q = $q + " FROM DMOHORN.EMPLOYEE" 
   9:   
  10:  $da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $cn) 
  11:   
  12:  $da.Fill($ds)
  13:   
  14:  $dtPerson = new-object "System.Data.DataTable" "dtEmployee" 
  15:  $dtPerson = $ds.Tables[0] 
  16:  $dtPerson | FOREACH-OBJECT { " " + $_.EMPNO + ": " + $_.FIRSTNME + ", " + $_.LASTNAME }
 
Powershell output was the following: 
 

PS_DB2_Output1

For those that cannot read the exception, it says:

Exception calling "Fill" with "1" argument(s): "The cursor specified in a FETCH statement or CLOSE statement is not open or a cursor variable in a cursor scalar function reference is not open. SQLSTATE: 24501, SQLCODE: -501"
At line:12 char:9
+ $da.Fill <<<< ($ds)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Later I changed the script to use the IBMDADB2 provider provided by IBM.  It is included as part of the DB2 Express installation.  I’m not 100% sure, but I believe these drivers also get installed by installing the DB2 Client and Drivers downloadable package

   1:  $cn = new-object system.data.OleDb.OleDbConnection("Provider=IBMDADB2;Database=SAMPLE;HostName=localhost;Protocol=TCPIP;Port=50000;Uid=DB2ADMIN;Pwd=mypassword;");
   2:   
   3:  $ds = new-object "System.Data.DataSet" "dsEmployee" 
   4:   
   5:  $q = "SELECT EMPNO"
   6:  $q = $q + ",FIRSTNME"
   7:  $q = $q + ",LASTNAME"
   8:  $q = $q + " FROM DMOHORN.EMPLOYEE" 
   9:   
  10:  $da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $cn) 
  11:   
  12:  $da.Fill($ds)
  13:   
  14:  $dtPerson = new-object "System.Data.DataTable" "dtEmployee" 
  15:  $dtPerson = $ds.Tables[0] 
  16:  $dtPerson | FOREACH-OBJECT { " " + $_.EMPNO + ": " + $_.FIRSTNME + ", " + $_.LASTNAME }

 

Powershell output was the following:

PS_DB2_Output2

I’m happy that I finally got this simple example working using Powershell.   I’m still uncertain why the code is failing using Microsoft’s DB2OLEDB provider both using Powershell and C#.   Maybe there is a bug with Microsoft’s driver using a DataSet?   I never did try using a DataTable.  I’ll save that little exercise to you, dear reader.

I’m still not a huge fan of DB2.  I think it is ackward to use and its tooling needs a lot of improvements.  Maybe I’m just too used to the quality of Microsoft’s SQL Server Management Studio.   Even Enterprise Manager and Query Analyzer runs laps around IBM’s clunking Control Center and newer Data Studio administrative tools.

I have a few more upcoming DB2 code samples to provide soon using Powershell’s hosting feature which allows me to run my scripts to create nice tabular reporting.  Stay tuned!

Hope you find this post useful.

author: David Mohorn | posted @ Saturday, January 14, 2012 7:27 PM | Feedback (0)

Monthly Microsoft Updates


I have a number of computers at home.  Even more virtual machines running on these computers. 

One of the most frustrating things I find about computers and Microsoft in general is it’s lack of concern for my work space or my time.

For example, I frequently  tend to have ten or more browser windows open on any one computer…  

I may have Notepad++ loaded with a number of files that I’m reviewing…

I may have Outlook open with an e-mail I’m in the middle of writing…

And I may even have Visual Studio 2010 project open to the exact source code line I was on before I finished for the day….

Most of the above may be on one computer or on one computer within a bunch of virtual machines…   Yes, I’m a VMware nut and enjoy having multiple virtual computers that are role/function specific.

I stopped working around 9PM last night to get the kids ready for bed, and ended up falling asleep myself.  (My fault, I guess…)

Today, around 2PM when I finally have time to resume where I left-off yesterday, after taking the kids to their swim class, coming home to feed them, and finally getting the little-one down for her afternoon nap… I was eagerly ready to continue working, only to find my computer had rebooted and was requesting that I log back in.   OK, all my virtual machines where abruptly shutdown.  Great!   Also checking around the room, I see my laptop had rebooted as well.

MS-Updates

I realize that the second Tuesday of this month was 01/10 and today is 01/14.   What I don’t appreciate is the fact that Microsoft decides that it’s important enough to apply my updates and reboot my computer for me.  Why can’t they just remind by default and not reboot unless I authorize?

I know I can go into Windows Update and change the behavior and tell it to only download and not apply, etc., but why MUST I do this on every machine by default.

I suppose I’ll take 15 minutes out of my day to hop around from computer to computer and turn off auto-updates…

Thanks Microsoft for giving me a wonderful user-experience.   I’m sure my mother would appreciate having her computer updated and recycling itself; since she is not as nearly as computer savvy as me; however, me on the other hand – I’d prefer to have control over how my machine is used!

Glancing over my shoulders, I see my iMac is still up-and-running where I left off.   Hmmm…. 

C’mon Microsoft, give me a better user-experience….   Windows still rocks, though!

author: David Mohorn | posted @ Saturday, January 14, 2012 3:22 PM | Feedback (0)

Connecting to a DB2 database using C#


Brief history:

I have been using Microsoft SQL Server since about 1995, when version 6.0 was the first version designed for Windows NT and was no longer a Sybase product.   Over the years, SQL Server has grown into an enterprise-worthy RDMS.  It’s tools are top-notch compared to other RDMS systems that rely on Java for its administrative tools. 

I have slowly been forced coerced to using IBM’s DB2 over Microsoft SQL Server at my job.  Not that DB2 is a better product.  Far be it…    It’s primarily due to company politics and the fact that our clients can install DB2 Express for free rather than having to pay for a SQL Server license.   Yes, I know there is SQL Server Express – but that’s not the point….   Bummer for me.  

Since this blog post is about DB2, I wanted to share with you my recent experience with trying to talk to DB2 using .NET and C#.  I have scoured the web trying to find decent examples that would work for me.   Something simple.   Unfortunately, there doesn’t seem to many folks  using DB2 that I can find – at least not the hobbyist.   Maybe using DB2 is a bit of a black art where only the elite few that work in big businesses know how to use.   Even IBM’s website seems to be outdated with its DB2 examples, only providing samples using Visual Basic 6.0 with some outdated from of DB2 that I don’t even remember or care about….

Similar to Microsoft SQL Server Express line, IBM has its own version of DB2 called DB2 Express.  As of this writing, the latest version of DB2 is DB2 Express-C 9.7.5.  It is available in both 32-bit and 64-bit form for Windows, Linux, and in beta for Mac OS X.   The Mac?  Are you serious?  Whatever…  You will need to create an account on IBM’s website to download, unfortunately.

In addition to downloading the core bits, you will likely want to download the “Data Studio Administration Client”.   This is another free tool that kind of replaced the Administrator Center…

IBM’s Control Center:

ControlCenter

IBM’s Data Studio:

DataStudio

You should also download the Visual Studio Add-on tools as well.  I personally haven’t used these, but they should provide you with direct access to DB2 from within the Visual Studio IDE.

Installation of DB2 is as simple as running the installer and then  agreeing to all the default prompts.    It should install the SAMPLE database which is very small compared to Microsoft’s Northwind or AdventureWorks, by the way.

There appears to be two kinds of providers you can use with DB2.   Either

  • DB2OLEDB
  • IBMDADB2

From my understanding, the DB2OLEDB is Microsoft’s .NET Provider.  I was able to get this provider to work, but I kept getting binding errors every time I tried to fill a DataSet from the query.   Switching to the IBMDADB2 provider seems to remedy all the other oddities I ran into.

An example connection string using both providers is below:

DB2OLEDB:

Provider=DB2OLEDB;User ID=your_username;Password=your_password;Initial Catalog=SAMPLE;Network Transport Library=TCP;Host CCSID=37;PC Code Page=1252;Network Address=your_host_IP;Network Port=50000;Package Collection=<collection>;Default Schema=<schema>;Process Binary as Character=False;Units of Work=RUW;DBMS Platform=DB2/NT;Defer Prepare=False;Persist Security Info=True;Connection Pooling=False;

IBMDADB2

Provider=IBMDADB2;Database=SAMPLE;HostName=your_host_IP;Protocol=TCPIP;Port=50000;Uid=your_user;Pwd=your_password

For the DB2OLEDB provider above, I’m not 100% certain if you need all those parameters,  but with my limited experience with DB2, it would seem to throw errors when I tried to remove other parameters…  The ConnectionStrings.com here website seems to have almost everything imaginable for any data source (Access, RDMS, Azure, etc.)   I encourage you to check them out.

OK, with all the introduction out the way, assuming you have downloaded DB2, installed the SAMPLE default database and can successfully access and log into DB2 using the Control Center, then the below code should work for you.   Note that for the IBMDADB2 provider, you will need to add a using statement for IBM.Data.DB2 namespace and a reference to your project.

DB2AddReference

The code sample below will execute a simple query against the SAMPLE database to a DataTable.  It will then export the rows from the DataTable to a .csv file within the C:\TEMP folder.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using System.Data.OleDb;
   5:  using System.Data;
   6:  using System.IO;
   7:  using IBM.Data.DB2;
   8:   
   9:   
  10:  namespace DB2TestConsole
  11:  {
  12:      class Program
  13:      {
  14:          static void Main(string[] args)
  15:          {
  16:              string connStringLocal = "Provider=IBMDADB2;Database=SAMPLE;HostName=your_host_IP;Protocol=TCPIP;Port=50000;Uid=your_user;Pwd=your_password;";
  17:              
  18:              OleDbConnection connLocal = new OleDbConnection(connStringLocal);
  19:   
  20:   
  21:              OleDbDataAdapter da_local = new OleDbDataAdapter(@"SELECT * FROM DMOHORN.EMPLOYEE", connStringLocal);
  22:   
  23:   
  24:              DataTable td = new DataTable();
  25:   
  26:              try
  27:              {
  28:                  
  29:                  da_local.Fill(td);
  30:              }                          
  31:              catch (Exception e)
  32:              {             
  33:                  Console.WriteLine("Exception: {0}", e.Message);
  34:              }
  35:   
  36:              // save to CSV
  37:              ExportDatasetToCsvFile(td, @"c:\temp\EMPLOYEE.csv");
  38:   
  39:          }
  40:   
  41:          static void ExportDatasetToCsvFile(DataTable table, string path)
  42:          {
  43:              StringBuilder str = new StringBuilder();
  44:              foreach (DataRow dr in table.Rows)
  45:              {
  46:                  foreach (object field in dr.ItemArray)
  47:                  {
  48:                      str.Append(field.ToString() + ",");
  49:                  }
  50:                  str.Replace(",", Environment.NewLine, str.Length - 1, 1);
  51:              }
  52:   
  53:              try
  54:              {
  55:                  System.IO.File.WriteAllText(path, str.ToString(), Encoding.UTF8);
  56:                  
  57:              }
  58:              catch (Exception ex)
  59:              {
  60:                  Console.WriteLine("Exception: {0}", ex.Message);
  61:                  
  62:              } 
  63:          }
  64:      }
  65:  }

 

In the future, I plan to blog about other simple utility apps I’m working on requiring DB2 access  for both automation, auditing, and change control.

Hope this helps!

author: David Mohorn | posted @ Thursday, January 12, 2012 9:07 AM | Feedback (0)

Expanding VMware Workstation .vmdk File using GParted


I have been a VMware Workstation fan-boy since 2002.  I’ve used the product since almost the beginning, using version 3.1.  The latest version is 7.1.

One of the things I most enjoy about using virtualization is the recoverability and time-savings it provides.  Having spent a number of hours and days/months rebuilding servers and desktops and tweaking my settings to the way I like them, I have been burned more times than I know of due to OS level errors or just some funky thing happens where the only option is to re-install Windows.

Since bad things always happen and having all my eggs in one basket creates additional risk, about five years ago I started creating virtual machine images for specific application functions/roles.  For example, I have a virtual machine image just for Office and e-mail.  I have another virtual machine image just for development; where Visual Studio, third party apps, my custom configuration settings, etc., reside.  I even have another virtual image for testing/demoing software downloads.  This one thing alone is what may cause any system to become unstable over time…

Today, I need to expand my .vmdk file for my development virtual machine so that I can install IBM’s DB2.  My .vmdk file size is was 65GB and I need to increase it to 73GB.  Now, if this was a physical PC, this typically isn’t an easy task – especially a HDD that is full.  Replacing the drive typically requires re-installing Windows, all your apps, settings, etc., the thing I was saying is a waste-of-time earlier…

Since I have 2TB drives for both internal and external storage on my system, there is plenty of room for growth.  However, I still try and be conservative with my storage, because I still need to backup my .vmdk across drives and/or network; which adds addition time for file copies.

The way I increase my virtual machine’s .vmdk image file size is two-fold.

  1. Use VMware Workstation console to expand the .vmdk to desired size.  I’m using VMware Workstation version 7.1.
  2. Use the open-source Gparted ISO to change your drive’s partition information.  GParted is a free partition manage that enables you to resize, copy, and move partitions without data loss.  As of this writing, version 0.11.0-7 is the latest.  I just so happen to be using 0.5.2-9; since it works and I have not had a need yet to upgrade.

Before you do continue, you should first back up your virtual machine’s image files – especially the .vmdk file.  Just in case something bad happens!  Because you know Murphy is always waiting for you!!!

The first thing you need to do is go to your virtual machine settings and under Hard Disk, click the “Utilities” button, and select “Expand…”.  From here, you can change your .vmdk’s file size.

image1

Here I changed my size to 73.0GB.  Hit “Expand” and prepare to wait, depending on how much you’re expanding.  This i

Image2

When done, you should get a friendly message as shown below.  Click “OK":

image3

Next, under your virtual machine settings, select your CD/DVD drive, then under “Use ISO image file”, click “Browse…” and select your downloaded GParted .iso file.  Click “OK” when done to save:

Image4

Start your virtual machine and the GParted O/S should come up:

Image5

   Accept all the defaults by pressing enter a few times…

Image6

Image7

After exiting GParted, it will shutdown and unmount the filesystem.  You may see something like:

Image10

Image8

Finally, the main screen will appear.  Shown below:

Image9

From here, you want to select your drive.  For example, /dev/sda1, which is my C: drive and then click the “Resize/Move” toolbar button.  A Resize/Move dialogue window will appear as shown below:

Image15

Click the right-arrow and drag the arrow to expand the partition to use the remaining space.  This will be the free space that you added to your .vmdk file from VMware Workstation.

Before:

Image16

After:

Image17

Finally, click the “Resize/Move” button.  You will then see the main GParted window again.  You must click the “Apply” toolbar button to make your changes stick.

Image18

Sometimes it’s a little bit tricky, but hit the “Exit” toolbar button and an Exit dialogue window should appear.  Select “Reboot” and GParted will be gracefully shutdown.  Sometimes this can take a while, depending on how big of a partition you have.

Image19

Here is the shutdown screen:

Image20

When GParted is shutdown, your system should reboot and you should see your Windows splash screen as shown below.

Image11

Then followed by a CHKDSK, since your partition table has been change.  Windows will now run a repair on the filesystem.   Let this run and don’t interrupt.

Image12

Once complete, you should be presented with your Windows logon screen.

At this point we are done.  From Windows, I will see the extra drive space.   When things begin to get tight again, I will simply follow the same steps I presented to expand the .vmdk file again.

Hope you found this tip useful!

author: David Mohorn | posted @ Wednesday, January 11, 2012 10:03 PM | Feedback (0)

Using Powershell to Compress and Delete IIS Logs


I’m always looking for ways to automate things as much as possible.

One of my current requirements is archiving and deleting old IIS logs on a couple of our Windows 2003 servers.  As a result, I ran across this script the other day by Bernie Salvaggio from http://www.berniesalvaggio.com and must say this is another example of a pretty elegant Powershell script.

With only a few changes to the folders and SMTP settings and downloading 7zip, this script worked beautifully.

   1:  #Windows PowerShell Code###################################################
   2:  # 
   3:  # NAME:     compress-remove-logs.ps1
   4:  # 
   5:  # AUTHOR:   Bernie Salvaggio
   6:  # EMAIL:    BernieSalvaggio(at)gmail(dot)com
   7:  # TWITTER:  @BernieSalvaggio
   8:  # WEBSITE:  http://www.BernieSalvaggio.com/
   9:  # 
  10:  # COMMENT:     Given one or more website directories, parse through the 
  11:  #            directory contents to find the previous month's IIS log 
  12:  #            files. Zip them up, verify     the .zip, and delete the original 
  13:  #            log files. The resulting compressed archive will be about 
  14:  #            4.5% of the size of the original log files.
  15:  #
  16:  #            This script is best utilized by setting a scheduled task 
  17:  #            to run it during off-peak times because the compression 
  18:  #            process will max out all available cores unless you tell 
  19:  #            7-Zip not to do so (in its own settings, not from this script)
  20:  # 
  21:  # REQUIRED: 7-Zip is required for this to work. By default this script 
  22:  #            looks for the 7-Zip executable, 7za.exe, in C:\7-Zip\
  23:  #
  24:  # You have a royalty-free right to use, modify, reproduce, and 
  25:  # distribute this script file in any way you find useful, provided that 
  26:  # you agree that the creator, owner above has no warranty, obligations, 
  27:  # or liability for such use. 
  28:  # 
  29:  ########################################################################### 
  30:   
  31:  # Build all the pieces for emailing results
  32:  $ServerName = gc env:computername
  33:  $SmtpClient = new-object system.net.mail.smtpClient
  34:  $MailMessage = New-Object system.net.mail.mailmessage
  35:  # Mail server settings for you to change according to your environment
  36:  $SmtpClient.Host = "192.168.1.200"
  37:  $MailMessage.from = ($ServerName + "@mydomain.com")
  38:  $MailMessage.To.add("yourname@mydomain.com")
  39:  $MailMessage.Subject = $ServerName + " IIS Log File Archive Results"
  40:   
  41:  # The folder(s) you want to back up
  42:  $TargetPaths = @("C:\TEMP\")
  43:   
  44:  # Where you want the backups saved
  45:  # There's a 1 to 1 relationship between the $BackupsPath and $TargetPaths 
  46:  # For each $TargetPaths you add, you need another $BackupsPath to go along with it
  47:  $BackupsPath = @("C:\TEMP\")
  48:   
  49:  # Short name to append to the filename of the .zip backup file (in case the backup path is the same for multiple target paths)
  50:  # Each entry here should match the corresponding one in the $TargetPaths array
  51:  $TargetPathName = @("iis-logs")
  52:   
  53:  # Temp file that stores the list of files for 7-Zip to archive
  54:  $ArchiveList = "c:\temp\listfile.txt"
  55:   
  56:  # Temp file used to write the 7-Zip verify results to, then read into the email message body
  57:  $ArchiveResults = "c:\temp\archive-results.txt"
  58:  $ArchiveExtension = ".zip"
  59:   
  60:  # Just some things to get started...
  61:  $TargetPathNameCounter = 0
  62:  $BackupPathCounter=0
  63:  $CurrentDate = Get-Date
  64:  $ArchiveDate = $CurrentDate.AddMonths(-1).ToString("MMMyyyy")
  65:   
  66:  # Path to the 7-Zip executable
  67:  $7z = "C:\Program Files\7-Zip\7z.exe"
  68:   
  69:  foreach ($TargetPath in $TargetPaths) {
  70:      # Directory list, minus the folders, where the last write time = the archive date, group the files by month/year
  71:      dir $TargetPath | where {!$_.PSIsContainer} | where {$_.extension -eq ".log"} | where {"{0:MMM}{0:yyyy}" -f $_.LastWriteTime -eq $ArchiveDate} | group {"{0:MMM}{0:yyyy}" -f $_.LastWriteTime} | foreach {
  72:          
  73:          # Generate list of files to compress. For list files, 7-Zip uses UTF-8 encoding by default
  74:          $_.group | foreach {$_.fullname} | out-file $ArchiveList -encoding utf8
  75:          
  76:          # Declare/Cleare the email message body
  77:          $MailMessage.Body = ""
  78:          
  79:          # Create the full name of the zip file we'll create
  80:          $ZipFileName = $BackupsPath[$BackupPathCounter]+$TargetPathName[$TargetPathNameCounter]+$_.name+$ArchiveExtension
  81:          
  82:          # Archive the list of files
  83:          $null = & $7z a -tzip -mx8 -y $ZipFileName `@$ArchiveList
  84:          
  85:          # Check if the operation succeeded
  86:          if($LASTEXITCODE -eq 0){
  87:              # If it succeeded, double check with 7-Zip's Test feature
  88:              $null = & $7z t $ZipFileName | out-file $ArchiveResults
  89:              if($LASTEXITCODE -eq 0){
  90:                  # Verify success, write out the contents of the verify command to the email message body
  91:                  foreach ($txtLine in Get-Content $ArchiveResults) {$MailMessage.Body += $txtLine + "`n"}
  92:                  # Delete the original files
  93:                  $_.group | Remove-Item
  94:              } else {
  95:                  $MailMessage.Body = "Error"
  96:              }
  97:          } else {
  98:              $MailMessage.Body = "Error"
  99:          }
 100:          $SmtpClient.Send($MailMessage)
 101:      }
 102:      Remove-Item $ArchiveList
 103:      Remove-Item $ArchiveResults
 104:      $BackupPathCounter++
 105:      $TargetPathNameCounter++
 106:  }

author: David Mohorn | posted @ Friday, January 06, 2012 11:19 AM | Feedback (0)

Getting the current DATE and TIME from BAT files


Most of the time, I prefer using Powershell for my scripting needs.  However, often times for simple tasks, it is too much work to get Powershell installed and configured across multiple servers… especially if the scripting task is very basic where Powershell is just overkill.

Since I often forget how to parse the DATE and TIME from DOS, I thought I’d blog about it.  I’ll probably have to refer to this post again from time to time, since I can never seem to remember.

Batch files can use the system variables %DATE% and %TIME% to get the current date and time of the system.  These variables return output in the following format, depending on region/location:

%DATE% returns DOW MM/DD/YYYY where DOW is day of week (Mon, Tue, Wed, etc.), MM is month (Jan, Feb, Mar), DD is day, and YYYY is year.

For example:

date

 

%TIME% returns HH:MM:SS:hh where HH is hour (in 24-hour format), MM is minute, SS is seconds, and hh is hundredths of seconds.

time

Now, what is really cool about these environment variables is that you can parse particular elements using a “:~” string; which returns a subnet of the variable.  Placing a number immediately following the :~ will provide the position to start with, and including a comma and another number, tells how many characters to include.   For example, %TIME:~0,2% returns the HH for hours or %TIME:~3,2% returns MM for minutes.  If you want the last two digits of a year, you would use %DATE:~-2%.  The “-2” indicates the last two characters of the string.  If you want a four-digit year, you would use %DATE:~-4%.

Here is  quick chart showing the most common values:

Item Variable
Current hour: %TIME:~0,2%
Current minute: %TIME:~3,2%
Current second: %TIME:~6,2%
Current day of week: %DATE:~0,3%
Current month: %DATE:~4,2%
Current day date: %DATE:~7,2%
Current year (2-digit): %DATE:~-2%
Current year (4-digit): %DATE:~-4%

author: David Mohorn | posted @ Friday, January 06, 2012 10:52 AM | Feedback (0)

Happy New Year 2012!


Happy New Year!!!

author: David Mohorn | posted @ Sunday, January 01, 2012 11:54 AM | Feedback (0)

The Wi-Fi Body Scale by Withings


withings

I’m typically a technology junkie, which means if it is wireless and allows me to monitor something, then it’s a must-have item for me.  I’ve had my eye on the Withings Wi-Fi Body Scale for some time now and decided it would be the perfect gift for the family this holiday season.

First, let me say that this scale is a bit pricey, but well worth the cost.   For me, I purchased it from Amazon for $159.99.   If you think your wife will be upset with you for spending this kind of hard-earned cash on a gadget, you’re absolutely wrong.  Yep!   This item passes the WAF (Wife Acceptance Factor).    Trust me.  Your wife having the ability to track her weight, etc., automatically each day and have the ability to review it by day, week, month, whatever… you’ll get plenty of brownie points!

What is unique and fun about this scale is that it monitors and records up to 8 members of your family’s weight, fat, muscle and BMI.   Every time you use the scale, it will transmit your information from the scale via Wi-Fi using your wireless network, out of the internet to Withings’ cloud services.   From there, you can use either your PC, iPhone or Android phone, or iPad or iPad 2 to review your health information instantly.

withings-mobile

I’m not going to spend a great deal of time reviewing this product.   There are some great reviews on Amazon here.  You can even watch their Youtube video below:

 

Setup was a breeze…

  1. Install 4 AAA batteries into bottom of scale
  2. Go to http://my.withings.com/en/#fromStartScale=true and follow the on screen instructions
  3. You will either create an account or use an existing account
  4. You will then download and install the software.
  5. Once software is installed, you will configure it for your wireless network’s SID and follow the on screen instructions
  6. You will plug your scale’s USB connection into your computer to configure it
  7. Once all done, you will disconnect your USB cable and can begin using your scale wherever you wish within your house.

Since I just got the scale a couple days ago, there isn’t much history or data recorded yet.   But I give this item 5-stars already for being easy to use and performing as advertised.   Next month this time, I should have some good data and will either be happy with my progress or totally discouraged at my inability to change my habits and weight.

Time will tell --

author: David Mohorn | posted @ Tuesday, December 27, 2011 11:01 PM | Feedback (1)

Upgrading FiOS Internet from 35/35 to 50/20


From 1997 until 2007, I had been both a Cox Internet (in Virginia) and Comcast Internet (Minnesota)  until Verizon FiOS became available in my neighborhood.  I quickly jumped on the fibre bang-wagon and haven’t looked back since.   FiOS handles my digital telephone, HD television along with DVR capabilities, and internet access.

If you’ve been reading this blog for a while, you’ve probably read some of my previous blog entries regarding FiOS.

This week, I upgraded my internet from a whopping 35/20 plan to their 50/20 plan.  I must say,  you don’t really appreciate what you have until you don’t have it any more… 

My internet speed has been blazingly fast –  but the extra bandwidth is nice when downloading software, video, and other content. 

Speedtest

author: David Mohorn | posted @ Friday, December 16, 2011 11:11 PM | Feedback (0)

Verizon FiOS Multi-Room DVR External Storage Expander


Verizon FiOS DVR Expander with IMG 1.9 and eSATA Storage

After about a year of waiting, this week I was presently surprised to see that Verizon had pushed out their IMG (Interactive Media Guide) firmware 1.9 to my area.  If you hang out in the Verizon forums, you can read posts from folks that have been waiting well over a year for this release.

Earlier this year, Verizon’s Joe Ambeault wrote an article on all the juicy goodness in this release.  In a nutshell

  • Device Support – All Motorola and Cisco set-top boxes will be upgraded to IMG 1.9 through automatic updates.  There is a small number of standard definition set-top boxes (Motorola QIP 2500 P1 and P2) that will stay on current release.
  • Lots of new features and enhancements – new look, redesigned search, Improved 3DTV support, and multi-room DVR enhancements.  There is plenty more…
  • New Look and Feel – Supports new HD canvas for 16:9 HD TV screens.  Old IMG 1.8 only supported 4:3 aspect ratio.
  • Next Generation Search – Searches are now off-loaded to distributed Verizon servers.  Better 1-click search access as well.
  • Parental Controls – Improvements made to usability to make it easier to enable.
  • Message Center – More sophisticated messaging from Verizon.
  • 3DTV – Cisco set-top boxes tht are HD capable and Motorola 7000 series devices will automatically configure your 3DTV to the proper 3D mode.  Motorola 6000 users are out of luck.
  • Self-service – Improved self-service using remote control.
  • DVR and Multi-room DVR – Now have the ability to expand storage capacity of DVR by using external drives.  This is supported on the Cisco DVD as well as Motorola 7000 series.

Engadget also wrote a nice review of IMG 1.9 here.   I encourage you to check it out.

A few weeks back, I was fortunate to upgrade my existing Samsung 42” LCD of 5 years to Vizio XVT3D650SV 65” LED/LCD 3D Theatre.  This unit required me to rethink my room layout and I ended up having to do some carpentry over my gas fireplace where a typical CRT TV would sit.   The new TV looks nice and basically freed up a wall in our living room.  I should add that this unit is not cheap and weights approx. 98 pounds without stand.   You can read the reviews here.

Since I needed to have FiOS come out to my house and reconnect the coax cable from the box inside to the box outside, I requested that if a newer DVR was available, I wanted it.   The tech said there was a new one and it had twice the capacity HDD (from 250GB to 500GB) but still used IMG 1.8.   However, he said sometime in November I could expect IMG 1.9.

At the same time, I learned that I could upgrade my existing set-top boxes in my three bedrooms from standard definition to HD.   Sweet!  One nice benefit of this is also the ability to manage my DVR library from other set-top boxes.  Now I can delete watched shows from upstairs without having to remember to remove it later when downstairs at my DVR!  Wife loves this, too!

Since my wife loves recording HD shows nowadays (they look awesome, right?), storage space is at a premium.   Luckily, with IMG 1.9, I can easily add an external eSATA drive (up to 1TB is supported using Verizon’s qualified drives).  This passed the WAF (Wife Acceptance Factor) as she uses the DVR more than me!

I ordered a 1TB My Book AV drive from Western Digital for $99.99, model WDBACS0010HBK-NEVZ.

image_2

Setup was virtually a snap by supplying power to the drive and plugging the eSATA cable from the drive into the eSATA port behind the set-top box as

image_4

shown below:

image_6

These are the drives qualified to work with Verizon multi-room DVRs:

image_8

The only issue that I experienced with hooking up the unit was that:

  1. eSATA drive power button on back of unit seems broken and the unit just stays in the ON position.  At least when I press the button it doesn’t do anything and the power light stays lit.
  2. Getting the DVR to recognize the eSATA drive was trial-and-error.  I’ve read various forum posts that say you have to power on/off the DVR and whatnot.  I tried this and when trying to activate the external storage from the DVR menu, it would pop up with a “cannot connect to server” error and abort.  After a few failed attempts, I then hit the power-off button on the DVR and it prompted for a reboot (first time this has happened).   Afterwards, it recognized the drive and I was able to provision it without issues.


Now when I look at the status of my storage, I can shift-right from local storage to external storage to see my space.  It’s too soon to say how I like it, but going from 250GB to now 1.5TB, I think the wife and I will have lots of HD shows to watch at our convenience and not have to worry about doing a lot of storage maintenance.

author: David Mohorn | posted @ Friday, December 16, 2011 11:10 PM | Feedback (1)

How to extract an MSI file from the command line


Every so often, I always find myself trying to remember how to extract an MSI file’s contents into a folder for some kind of custom network deployment.

To extract files from an .msi file at the command line:

msiexec /a PathtoMSIFile /qb TARGETDIR=Directorytoextractto

If using the command line isn’t your thing, there is a nice GUI program that integrates with Windows Explorer called “lessmsi” (formerly Less Msierables) by Scott Willeke.     It is available from Google code here.

msi_2_2

author: David Mohorn | posted @ Friday, December 16, 2011 11:09 PM | Feedback (0)

Master-Powershell


This may be old news for some folks, but today I ran across “Master-Powershell | with Dr. Tobias Weltner” and wanted to pass it along.   This is an ebook and appears to have a lot of the Powershell specific things I’m always hunting for via Google search.

You can download the entire PDF version here.

The following is a list of chapters:

Chapter 1 – The PowerShell Console
Chapter 2 – Interactive Powershell
Chapter 3 – Variables
Chapter 4 – Arrays and Hashtables
Chapter 5 – The Powershell Pipeline
Chapter 6 – Using Objects
Chapter 7 -  Conditions
Chapter 8 – Loops
Chapter 9 – Functions
Chapter 10 – Scripts
Chapter 11 – Finding and Avoiding Errors
Chapter 12 – Command Discovery and Scriptblocks
Chapter 13 – Text and Regular Expressions
Chapter 14 – XML
Chapter 15 – The File System
Chapter 16 – The Registry
Chapter 17 – Processes, Services, Event Logs
Chapter 18 – WMI: Windows Management Instrumentation
Chapter 19  - User Management
Chapter 20 – Your Own Cmdlets and Extensions

There is also an additional chapter that is not part of the PDF.

Administrator’s Guide to Powershell Remoting

I now wish that I ran across this content before purchasing my other Powershell books…. as this one seems to be the most useful!

author: Blog Author | posted @ Friday, December 16, 2011 11:06 PM | Feedback (0)

How to Determine IIS AppPool’s PID


Today I had an issue with some web applications that were misbehaving.   Since we have multiple AppPools setup, I needed a way to determine each AppPools PID.  Fortunately, Microsoft provides a nice little iisapp.vbs script that works nicely.   Here is how to determine what AppPool goes to what W3WP.EXE.

1) Launch Task Manager

2) Select “Processes” tab, go to “View” and select “Select Columns…”.

3) You will need to select “PID (Process Identifier)”.    Then click “OK” button.

image_4_2

4) Scroll down until you find “W3WP.EXE”.  You will have one of these for each AppPool.

image_2_2

5) Go to DOS Prompt, and CD to C:\WINDOWS\SYSTEM32 folder.  

6) Run CSCRIPT IISAPP.VBS.   You will get the following output:

image_6_2

7) Go back to Task Manager and find the PID that corresponds with the AppPool name that you created.

Hope this helps!

author: David Mohorn | posted @ Tuesday, August 02, 2011 4:53 PM | Feedback (0)

Dell Patents “Reboot and See If That Fixes It” Technical Support Process


This may be old news, but I stumbled the blog post “Dell Patents ‘Reboot and See If That Fixes It’ Technical Support Process” and thought I’d share it with you here.

image_2_2

This reminds me of what Albert Einstein once said “The definition of insanity is doing the same thing over and over again and expecting different results”.  

Let me reboot now and see if Windows Live Writer fixes my spelling mistakes…

author: David Mohorn | posted @ Tuesday, July 19, 2011 11:10 PM | Feedback (0)

The version of Dbghelp.dll configured does not support the Microsoft Symbol Server


The version of Dbghelp.dll configured does not support the Microsoft Symbol Server.

I have been using Mark Russinovich’s Sysinternals Tools for Windows for a number of years.  Since I have been using the same binary without updating for a while, I thought it would be good to download the latest Sysinternals Suite.    This download contains a roll up of all the tools and help files.

I stumbled across the below warning when using the latest Process Explorer and clicking on a process and trying to view the threads:

image_2_2

This message is telling me that my current Dbghelp.dll that I have installed is not compatible for the Microsoft Symbol Server.   To correct, I need download and install the latest Microsoft Debugging Tools for Windows.  Make sure you select “Windows Debugging Tools”; otherwise you’ll just install the SDK.  Afterwards, launch Process Explorer, go to Options | Configure Symbols… and dialog window will open:

image_4_2

And then under “Dbghelp.dll path”, browse out to where you installed the Debugging Tools.   Here it was under C:\Program Files\Debugging Tools for Windows (x64)\srcsrv\ and select the dbghelp.dll

You may also want to configure “Symbols path” to the location you have configured within WinDbg for downloading your symbols as well.

image_6_2

To configure WinDbg Symbol path, launch WinDbg, go to File | Symbol File Path… and dialog window will open:

image_10_2

and ensure you have srv*c:\symbols\publics*http://msdl.microsoft.com/download/symbols path defined as shown below:

image_8_2

Hope this helps!

author: David Mohorn | posted @ Tuesday, July 19, 2011 10:50 PM | Feedback (0)