Pages

Tuesday, November 30, 2010

Create Image files from MS SQL Image Data Type with Powershell

Today my brother Patrick asked me to pull pictures from our ID badge System to be used for Active Directory. I found that the images where stored in a Microsoft SQL 2000 instance as the image data type. After some work with Powershell I was able to to recreate the Image file from the SQL data. This example is of course a simplifed version but should be easy enough to modify for your needs.

$picture_ID = 1
$file = "c:\image.jpeg"
$sqlserver = "DBServer"
$SQLCommand = "Select image 
  From ImageTable
  Where ID = '$picture_ID'"
#note image is an SQL Type "Image"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$sqlserver;Database=master;Integrated Security=True"
$SqlConnection.Open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SQLCommand
$SqlCmd.Connection = $SqlConnection
$dbname = $SqlCmd.ExecuteScalar()
$SqlConnection.Close()

Set-Content -path $file -Value $dbname -Encoding Byte 
start $file #open the file to view if its correct.

In my case I didn't know the files were jpeg but used http://www.sqlimageviewer.com/ to first see what type of tiles they are. Then change the file extension. Also the trial was sufficient for this, no need to buy it.

Additionally I modifyed a fuction from Jason Fossen to demo the return array when it was returned as a string to create a byte array and

function Convert-HexStringToByteArray {
Param ( [String] $String )

#Clean out whitespaces and any other non-hex crud.
$String = $String.ToLower() -replace '[^a-f0-9\\\,x\-\:]',''

#Try to put into canonical colon-delimited format.
$String = $String -replace '0x|\\x|\-|,',':'

#Remove beginning and ending colons, and other detritus.
$String = $String -replace '^:+|:+$|x|\\',''

#Maybe there's nothing left over to convert...
if ($String.Length -eq 0) { ,@() ; return } 

#Split string with or without colon delimiters.
$String -split '([a-f0-9]{2})' | foreach-object { 
 if ($_) {
   [System.Convert]::ToByte($_,16)  
 }
} 
}

$file = "c:\image.jpeg"
$img = "0xFFD8FFE000104A46......" #excluded the rest for size reasons
$ba = Convert-HexStringToByteArray $img
Set-Content -path $file -Value $ba -Encoding Byte 
start $file #open the file to view if its correct.

Monday, November 29, 2010

Create LTO Barcode Labels

This post is more for my own memory than yours. A while back I needed to reuse some LTO cleaning cartridges. However the IBM Tape Library we use needed LTO bar codes on the tapes and they didn't have any.  I priced the labels and found the it way overpriced for simple barcodes. Rather than spending the money I followed the post here on how to create the needed LTO bar codes.

The reason I'm posting this is because it happened again with new cleaning cartridges that got ordered with out labels and I had to find out to print them again.  I did find a few products that would create the labels  and print them however they weren't free and I only needed about 10 labels.

Site what we followed: http://rogierg.blogspot.com - 80 bucks for LTO barcodes? WTF?
Create Barcodes Site: http://www.barcodesinc.com/generator/index.php

Settings for the LTO Barcode
LTO Barcode Creation




After you generate the barcode, right click the image and "Save image as" and save the jpeg. Print the label and carefully tape it to the LTO Cartridge. Be careful that there is no way the barcode can come free or hang in anyway.

Tuesday, November 23, 2010

VMware View 4.5 - Removing the linked clone references from the View Composer Database

In an earlier post I referenced Manually deleting linked clones or stale virtual desktop entries from VMware View Manager. While following that KB my self I found removing references from the View Composer database to be to much of a manual process and double so when removing multiple machines in a pool. I went looking on line and found nearly what I wanted from wanted from andga.

I made just a few changes to what andga wrote so that it would work work with the BaseName and will remove the references from all tables based on the name. By using sql 'like' and '%' it finds all the matching VM and cleans them all up at once.

DECLARE @vmdelete varchar(20);
set @vmdelete = 'VM_BaseName%';

delete from SVI_VM_NAME where NAME like @vmdelete
delete from SVI_COMPUTER_NAME where NAME like @vmdelete
delete from SVI_TASK_STATE where SIM_CLONE_ID in (SELECT ID FROM SVI_SIM_CLONE WHERE (VM_NAME like @vmdelete))
delete from SVI_SC_BASE_DISK_KEYS where PARENT_ID in (SELECT ID FROM SVI_SIM_CLONE WHERE (VM_NAME like @vmdelete))
delete from SVI_SC_PDISK_INFO where PARENT_ID in (SELECT ID FROM SVI_SIM_CLONE WHERE (VM_NAME like @vmdelete))
delete FROM SVI_SIM_CLONE WHERE (VM_NAME like @vmdelete)

After using this or manually editing the SQL in the View Composer DB be sure to restart the VMware View Composer Service.

Links

VMware View 4.5: Specified AD container partial distinguished name is not valid

Update 9-1-2011 with View 4.6 - Ran into this problem again, it seems that if you change the creds in view that they don't take effect very quickly. I made a change to the creds for the vSphere one day and 2 days later recomposing started giving the "Specified AD container partial distinguished name is not valid"  again. Check the AD permissions on the OU you have the View VM's added to with this post by Vmware. Also it was creating the AD objects then failing, as clean up Manually deleted those objects from AD.

Today I kept getting the following in error in VMware View 4.5 when trying to provision VMs.
Specified AD container partial distinguished name is not valid.
When provisioning VMware View Pools. I've ran into it error before and last time i was in a hurry and created a new pool to get around the problem. However I finally narrowed it down several causes today.
  1. Follow the Logs. For more detailed information checkout "\\VSphereServer\c$\ProgramData\VMware\View Composer\Logs\vmware-viewcomposer.log" for additional detail about the error.
  2. Is the Value correct? If your like me you used the GUI to set this value so it seems unlikely its incorrect.  
  3. Does that account specified have access to add machines to that OU and is the password correct. Both are easy to check, as the password might have changed or the like.
  4. Did the Computer already exist in AD? If your recomposing the machine you may need to delete the already existing AD object and then see if it can recreate it.
  5. Have you rebooted the View Composser Server? I found that while the services were up I needed to reboot it once in a while. I don't know why this is and it shouldn't work but I found that it did. Wish i could tell you more on why this works some times.
  6. Try Removing it from the LDAP ADAM instance, the DB, and View before provisioning it. Manually deleting linked clones or stale virtual desktop entries from VMware View Manager
If unsure how to connect to the LDAP Instance look to my other post.

If you are seeing the following also follow the Manually deleting linked clones or stale virtual desktop entries from VMware View Manager link. You may need this post if your deleting references from the View Composer database as it will automate the process for you.
Desktop Composer Fault: 'Virtual Machine with Input Specification already exists



Links

Unprotect or Delete VMware View Replicas

7/20/2012 Update: The below post pertains to pre view Composer 3.0. See this document for more information.

Ever have a VMware View Replica shown in vSphere Client but unable to move, edit, or delete it? I have.  First assume you really know what your doing and you need to modify it. Normally VMware View attempts to protect you from yourself and protects your replicas, even from you. But sometimes you may need to mofity them anyway and to do so you'll need to remove the protection.

To do this you will need to use the SviConfig Command on the View Composer server. The Syntax on it usage isn't to hard but the inventory path wasn't very clear. Thus the  problem is figuring out the syntax in order to remove the connection. As a Solution   This is a Powershell script that will display the correct syntax to remove the VMware View Protection from the replica. SviConfig usage for unptotectentity are as follows:
sviconfig -operation=unprotectentity
          -VcUrl=https://<VirtualCenter address>/sdk
          -Username=<VirtualCenter account name>
          -Password=<VirtualCenter account password>
          -InventoryPath=/<Datacenter name>/[vm|host]/<folder name>/<vm name>
          -Recursive=[true|false]

What I wrote is a powershell Script that generates the unprotect commands. The script requires the VMware vSphere PowerCLI to be installed but doens't have to be run from the View Composer server. This script only creates the commands, it does not execute sviconfig in anyway.  Instead it Creates the commands and puts them in a text file then shows you the text file.

Download UnprotectVmwareViewReplicas.ps1

Example Output
Output of Unprotect Replicas Commands 

Monday, November 22, 2010

How to Connect to VMware View's LDAP Instance with AdsiEdit

As part of my VMware View 4.5 setup I've needed dig into the LDAP instance that Vmware View uses. In case you didn't know Vmware View usesa  LDAP instance (using Microsoft's ADAM) to allow additional connection Servers to be used to provide high‐availability and load balancing.  The connection is easy enough with adsiedit.msc if know if you know the Naming Context.

I warn you to manually edit this LDAP at your own risk.
  • From a server or Desktop that has the AD tools installed run  adsiedit.msc from a console window or Run prompt.
  • Right click ADSI Edit and then connect to...
  • Change the Connection Point to DC=vdi,DC=vmware,DC=int
  • Select the the Computer and enter the name of your VMware View Host.
AdsiEdit Connection Settings for VMware View 4.5

Thursday, November 18, 2010

Emulex 10 Gb CNA Crash - VMware and Windows Update 1

Following up a previous post of mine on our Emulex 10 Gb CNA problems and crashes. I figured I'd take a minute and update the list of working driver builds we've used  for VMware ESX hosts.

  • Version: be2net-2.102.486.0
    • VMware ESX Versions: 4.0 and 4.1
    • ISO: esx-4.0.0-GA-be2net-2.102.486.0.iso
    • Release: Beta
    • Verdict: STABLE
    • Obtained: Our Networking Admin got it emailed from Emlex Systems Engineer  
  • Version: be2net-2.102.474.1
    • VMware ESX Versions: 4.0 and 4.1
    • ISO: esx-4.0.0-GA-be2net-2.102.474.1.iso
    • Release: Beta
    • Verdict: STABLE
    • Obtained: Our Networking Admin got it emailed from Emlex Systems Engineer  
    • Obtained on: 9/20/2010