FBA login page not showing up

August 29th, 2009

If you have setup FBA and cannot see the fba login page then here is one thing to check…

When you add the required parts to the web.config files make sure that:

1.  The initial connection string for the central admin web.config is just under the </sharepoint> tag.

2.  The other two that need to be added to the <system.web> tags need to be under the LAST <system.web> tag and needs to be the LAST thing in between the tags.  That means it needs to end on the line just before you see </system.web>.  (A tip for this is to search for <system.web> and click next until you reach the last one.  Then find your way from there.

Categories: .net FrameWork, FBA, MOSS, Project Server, SharePoint

No Comments

Unknown Error - Issues with FBA via SharePoint

August 24th, 2009

Getting this error when you login via FBA to SharePoint?  Ahhh… chances are that you did not perform the undocumented step!

You MUST have the user you setup to run the FBA web application as the DBO role on the FBA database.

Categories: .net FrameWork, FBA, Project Server, SharePoint

Tags: , , , , , , No Comments

Comparing files via checksum with Powershell

August 1st, 2009

Have you ever had to push Gigabytes of files accross the network, knowing that the same version of many of those files already existed on the other end, but you didn’t have an immediate way of checking which ones were already in place?

If so, we can mitigate that problem somewhat with checksums.

Below is a simple function that will give you the checksum for a given file. For the sake of space and time, I’ve kept the function pretty minimal.

function Get-Checksum($file, $crypto_provider) {
	if ($crypto_provider -eq $null) {
		$crypto_provider = new-object 'System.Security.Cryptography.MD5CryptoServiceProvider';
	}		

	$file_info	= get-item $file;
	trap { ;
	continue } $stream = $file_info.OpenRead();
	if ($? -eq $false) {
		return $null;
	}

	$bytes		= $crypto_provider.ComputeHash($stream);
	$checksum	= '';
	foreach ($byte in $bytes) {
		$checksum	+= $byte.ToString('x2');
	}

	$stream.close() | out-null;

	return $checksum;
}

Let’s look at it in further detail.

It takes in the full path to a file as an argument, and an optional argument of your crypto provider of choice. If none is specified, it will default to using The MD5 crypto provider.

function Get-Checksum($file, $crypto_provider) {
	if ($crypto_provider -eq $null) {
		$crypto_provider = new-object 'System.Security.Cryptography.MD5CryptoServiceProvider';
	}

Next, get the file, then attempt to read it in as a stream. If we are unable to open it, the function simply returns null instead of processing it further.

$file_info	= get-item $file;
trap { ;
continue } $stream = $file_info.OpenRead();
if ($? -eq $false) {
	return $null;
}

Next, call the ComputeHash method of the provider on the stream to create a byte array, and then create our empty checksum. For each byte, convert it to hexadecimal, then add it to the checksum.
(more…)

Categories: PowerShell

Tags: , 2 Comments

Disabling Admin UAC with Powershell

July 31st, 2009

Well apparently some people don’t like User Account Control getting in the way of the Administrator account(s), and so they need a way to disable this annoying
behavior. Here’s a quick function I threw together today at the request of a friend, that will do just that. Please excuse the formatting…

function Set-AdminUAC([int] $value = 0) {
$computers	= @($input);
if ($computers.count -lt 1) {
	$computers += @('.');
}
$results	= @{};
$hkey_lm	= 'LocalMachine';
$hkey_cr	= 'ClassesRoot';
$path_system	= 'Software\Microsoft\Windows\CurrentVersion\Policies\System';
$path_clsid	= 'CLSID';
$id_notify	= '{FD6905CE-952F-41F1-9A6F-135D9C6622CC}';
$prompt_admin	= 'ConsentPromptBehaviorAdmin';

foreach ($computer in $computers) {
	$success	= $false;

	trap { ;
	continue } $reg_lm	= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey_lm, $computer);
	if ($? -eq $false) {
		$results.$computer = $success;
		continue;
	}
	$reg_cr		= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey_cr, $computer);

	$key_system	= $reg_lm.OpenSubKey($path_system, $true);
	if ($key_system -ne $null) {
		foreach ($index in 0..1) {
			$value_admin	= $key_system.GetValue($prompt_admin);
			if ($value_admin -eq $value) {
				$success = $true;
				break;
			}
			else {
				trap { ;
				continue } $key_system.SetValue($prompt_admin, $value, 'Dword') | out-null;
				if ($?) {
					$key_system.Flush() | out-null;

					$key_clsid	= $reg_cr.OpenSubKey($path_clsid, $true);
					$subkeys	= @($key_clsid.GetSubKeyNames());
					if (($key_clsid -ne $null) -and ($subkeys -contains $id_notify)) {
						$key_clsid.DeleteSubKey($id_notify) | out-null;
						$key_system.Flush() | out-null;
						$key_clsid.Close() | out-null;
					}
				}
			}
		}
		$key_system.Close() | out-null;
	}
	$reg_lm.Close() | out-null;
	$reg_cr.Close() | out-null;
	$results.$computer = $success;
}
	return $results;
}

(more…)

Categories: PowerShell, Server 2008

Tags: , , No Comments

Checking for pending reboots with PowerShell

July 29th, 2009

I found out the hard way a few days ago that our old, tried-and-true method of determining if there were pending reboots had changed with the latest Windows Server OS, Server 2008. In the old days (last year), we could check for pending reboots on Windows 2003 simply by looking at the ‘PendingFileRenameOperations’ property in the registry, but now with Server 2008, times have changed.

I have now tasked myself with spending quality time with a Server 2008 VM and a copy of ProcessMonitor, so as to see if I can find a new way to determine this sometimes-critical piece of information. Unfortunately, I have not yet found a 100% reliable way of getting this information, but I’d like to share what I’ve found so far.

function Get-PendingReboot($computer = '.') {
	$hkey		= 'LocalMachine';
	$path_server	= 'SOFTWARE\Microsoft\ServerManager';
	$path_control	= 'SYSTEM\CurrentControlSet\Control';
	$path_session	= join-path $path_control 'Session Manager';
	$path_name	= join-path $path_control 'ComputerName';
	$path_name_old	= join-path $path_name 'ActiveComputerName';
	$path_name_new	= join-path $path_name 'ComputerName';

	$pending_rename	= 'PendingFileRenameOperations';
	$pending_rename_2	= 'PendingFileRenameOperations2';
	$attempts	= 'CurrentRebootAttempts';
	$computer_name	= 'ComputerName';

	$num_attempts	= 0;
	$name_old	= $null;
	$name_new	= $null;

	$reg= [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $computer);

	$key_session	= $reg.OpenSubKey($path_session);
	if ($key_session -ne $null) {
		$session_values	= @($key_session.GetValueNames());
		$key_session.Close() | out-null;
	}

	$key_server	= $reg.OpenSubKey($path_server);
	if ($key_server -ne $null) {
		$num_attempts = $key_server.GetValue($attempts);
		$key_server.Close() | out-null;
	}

	$key_name_old	= $reg.OpenSubKey($path_name_old);
	if ($key_name_old -ne $null) {
		$name_old = $key_name_old.GetValue($computer_name);
		$key_name_old.Close() | out-null;

		$key_name_new	= $reg.OpenSubKey($path_name_new);
		if ($key_name_new -ne $null) {
			$name_new = $key_name_new.GetValue($computer_name);
			$key_name_new.Close() | out-null;
		}
	}

	$reg.Close() | out-null;

	if ((($session_values -contains $pending_rename) `
	-or ($session_values -contains $pending_rename_2)) `
	-or (($num_attempts -gt 0) -or ($name_old -ne $name_new))) {
		return $true;
	}
	else {
		return $false;
	}
}

(more…)

Categories: PowerShell, Server 2003, Server 2008

Tags: , 3 Comments

Affinity or Sticky Sessions

July 24th, 2009

So what is Affinity? It is sticky sessions.. :)
Then what is this “sticky session” thing you speak of?

Well when you connect to a website with NLB you are being passed from one server to the next depending on how many nodes or hosts you have.  Every time you click a link it will essentially open a new connection which means if you were using Server1 and it is now server2’s turn to server a request then you will be moved to server2.

OK, so whats the big deal?

Well once it opens a new connection it will not save any info because it sees it as a new connection… This is a HUGE issue if you have to login to an app that is using NLB and you are sent to another server… you will have to re-login.  So what sticky sessions does is allow you to use the same connection for all requests until you close the browser or leave the site.

Categories: NLB

1 Comment

Setup NLB in Windows Server

July 24th, 2009

I see alot of questions on how to setup NLB with Windows Server operating systems…  Especially utilizing SharePoint and Project Server.  So this will be a part 1 per say… setting up NLB in Windows Server 2003.  Setting this up in Server 2008 should be pretty much the same if not identical.

So to get started and do this the correct way you will need 4 network cards and a minimum of 5 IP addresses.  (There is a way to do this with less which I will do a tutorial on a later date)
2 IP’s for standard access nics
2 IP’s for NLB connected nics (These MUST BE static IP addresses)
1 IP for Cluster IP address (You can have more than 1 but 1 is minimum)  You will also need a DNS entry for this IP if you want to use it for websites.  (MUST BE Static IP)

For my example I will be using:  10.1.1.24 - 10.1.1.28
10.1.1.24 and 10.1.1.26 will be my standard nics
10.1.1.25 and 10.1.1.27 will be NLB Connected nics (These MUST BE static IP addresses)
10.1.1.28 will be used for NLB address (MUST BE Static IP) (more…)

Categories: NLB, Server 2003

Tags: , No Comments

Base64 encoding and decoding with PowerShell

July 19th, 2009

A few days ago, I needed to perfom some simple obfuscation on a string. Since I had used Base-64 encoding for this purpose in the past, I needed to find a quick way to perform Base-64 encoding and decoding with PowerShell. Surprisingly, I couldn’t find a blog post or tutorial detailing a simple, straight-forward way of performing this task, though I knew it was easy to do. Since it took me a while to sort it out, I figured that it would be a good idea to throw together a couple of functions for public consumption.

First we have the encode function.

function ConvertTo-Base64($string) {
   $bytes  = [System.Text.Encoding]::UTF8.GetBytes($string);
   $encoded = [System.Convert]::ToBase64String($bytes); 

   return $encoded;
}

Then, we have the decode function.

function ConvertFrom-Base64($string) {
   $bytes  = [System.Convert]::FromBase64String($string);
   $decoded = [System.Text.Encoding]::UTF8.GetString($bytes); 

   return $decoded;
}

Simple, straight forward. Also notice that I used UTF8 for the initial encoding. Feel free to substitute for UNICODE or whatever, as per your requirements. For a list of what’s available
(more…)

Categories: PowerShell

Tags: No Comments

Enable Self-Serve Site Creation via Central Admin

July 13th, 2009

Want to do this from stsadm? go here

Open your central admin site:  http://servername:port  (Example:  http://testserver:1234) and login as a farm admin.

Navigate to the “Application Management” tab

Application Management tab in Central Administration

Application Management tab in Central Administration

(more…)

Categories: Uncategorized

1 Comment

Verifying valid email addresses with PowerShell…sort of…

July 11th, 2009

I was recently asked to whip up a quick function that would verify email addresses from a list, and extract the ones that were valid and unique. Apparently, someone had run a report which should have resulted in a list of email addresses, sent it to the requester, and then left for the day. Unfortunately, they ran it incorrectly, and the results were a mix of email addresses, names, LDAP paths, partial home addresses, and the like…in fact, tens of thousands of lines worth.

Now, if your familiar with email address standards, you know that there’s a very complex set of characters which would be considered valid for an email address. I’ve seen huge multi-line RegExes designed to verify *almost* any valid email address, and fortunately for me, I’m not interested in showing you any of those here. The fact is, they all fall short in some way. Instead, I’m going to show you a simple RegEx that should catch a majority of modern email addresses. The key is to know who’s standard you’re parsing for, and the company that I did this for has a strict one-or-more-word-characters along with one-or-more-dots standard on either side of the “@”.

Let’s look at it.

function Get-ValidAddresses() {
	$lines			= @($input);
	$addresses		= @();
	$addresses_unique	= @();

	$pattern_address = '(?<Address>[\w\.\+]+@[\w\.]+)';
	$pattern_replace = '(\A\.+|\.+\Z)';

	foreach ($line in $lines) {
		if ($line -match $pattern_address) {
			$addresses += @($matches.Address);
		}
	}

	$addresses = $addresses -replace $pattern_replace, '';
	$addresses_unique = @($addresses | sort-object -unique);

	return $addresses_unique;
}

First, we take in the piped input and assign it to an array. I like to avoid using the default/built-in variables where possible (a practice that was reinforced by what I read in Perl Best Practices a few years ago). Anyway, then set up a couple of arrays to store our email addresses in. After that, we set up our Regular Expressions for verifying which email addresses we believe to be valid.
(more…)

Categories: PowerShell

Tags: , No Comments

Feed

http://www.techmumbojumblog.com /