Error in ShouldIProvision

Jun 17, 2011 at 7:09 PM

Hey!

Well, there is a small (but significant) error in the function - it is case sensitive!

if you mix upper and lower case computernames, it doesn't equal true (mycomputer != MYCOMPUTER)

So, I re-wrote the function to the following:

function ShouldIProvision([System.Xml.XmlNode] $node)
{
	$returnval = $false;
	$pcname = ($env:ComputerName).ToUpper();
	
	# Allow for comma- or space-delimited list of server names in Provision or Start attribute
	if ($node.GetAttribute("Provision")) {$v = $node.GetAttribute("Provision").Replace(","," ")}
    	elseif ($node.GetAttribute("Start")) {$v = $node.GetAttribute("Start").Replace(","," ")}
	
	if ($v -eq $true) { Return $true; }
	
	$v = " " + $v.ToUpper() + " ";
	
	if ($v.IndexOf(" " + $pcname + " ") -ge 0) { $returnval = $true; }
	else { $returnval = $false; }
	
	return $returnval;
}

Now it doesn't care what case the names are in - all are converted to uppercase (and it correctly matches the $v with the current computername)
Cheers!
/Jesper
Coordinator
Jun 23, 2011 at 4:19 AM

Thanks Jesper - I've implemented your fix and will check it in soon.

Thx
Brian