<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">The Technical Adventures of Adam Weigert</title><subtitle type="html" /><id>http://weblogs.asp.net/adweigert/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/adweigert/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2004-03-09T12:14:00Z</updated><entry><title>PowerShell: Keeping Secrets for Batch Scripts</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2008/08/27/powershell-keeping-secrets-for-batch-scripts.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="929" href="http://weblogs.asp.net/adweigert/attachment/6571947.ashx" /><id>http://weblogs.asp.net/adweigert/archive/2008/08/27/powershell-keeping-secrets-for-batch-scripts.aspx</id><published>2008-08-27T16:01:00Z</published><updated>2008-08-27T16:01:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;As a system administrator, I write a lot of utility scripts, and I love using PowerShell. However, I cannot always use the local scheduler with a service account to run a script, sometimes I have to provide a username and password to an application or service. I hate storing them in plaintext, and while I don't fully like storing the encrypted text, key, and IV in the script, it is one step better than the plaintext solution. While the ultimate solution would be to have it stored as part of the user profile for the job, this is an issue when I don't have direct access to the production system to be able to run as the service account and I just need an encrypted file / text to later decrypt and use. &lt;/P&gt;
&lt;P mce_keep="true"&gt;So, I started working with ConvertTo/From-SecureString and hit a little problem. I discovered, via Reflector, that the ConvertTo-SecureString and ConvertFrom-SecureString use an IV that is specific to that instance of the PowerShell runtime. Thus, using it at a later time is no good for me. So, long story short, I cranked up Reflector, took a look at the commands, and created a script version that does exactly what I need. &lt;/P&gt;
&lt;P mce_keep="true"&gt;You will find the script attached.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6571947" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /><category term="cryptography" scheme="http://weblogs.asp.net/adweigert/archive/tags/cryptography/default.aspx" /></entry><entry><title>PowerShell: Adding the Using Statement</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2008/08/27/powershell-adding-the-using-statement.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2008/08/27/powershell-adding-the-using-statement.aspx</id><published>2008-08-27T15:56:00Z</published><updated>2008-08-27T15:56:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;So, I happened to come across a need for the using statement from C#. I basically didn't want to use Try...Finally when I am so used to the short-hand using statement. Thank goodness I already have a &lt;A class="" title=Try...Catch...Finally href="http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx" mce_href="http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx"&gt;Try..Catch..Finally&lt;/A&gt; statement/function for PowerShell, I can just use that existing framework and make a using statement/function pretty easily.&lt;/P&gt;
&lt;BLOCKQUOTE style="FONT-FAMILY: courier,monospace"&gt;&lt;PRE&gt;function Using {
    param (
        [System.IDisposable] $inputObject = $(throw "The parameter -inputObject is required."),
        [ScriptBlock] $scriptBlock = $(throw "The parameter -scriptBlock is required.")
    )
    
    Try {
        &amp;amp;$scriptBlock
    } -Finally {
        if ($inputObject -ne $null) {
            if ($inputObject.psbase -eq $null) {
                $inputObject.Dispose()
            } else {
                $inputObject.psbase.Dispose()
            }
        }
    }
}

# Short example ... 
Using ($user = $sr.GetDirectoryEntry()) { 
  $user.displayName = $displayName 
  $user.SetInfo() 
} 
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;Update: Take note on variable scope, variables in the using statement will not be available outside of it, this can make it tricky, but it should be easy enough to work with.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6571855" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /></entry><entry><title>PowerShell: Threading Enhancements FTW!</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2008/04/30/powershell-threading-enhancements-ftw.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="1105" href="http://weblogs.asp.net/adweigert/attachment/6144660.ashx" /><id>http://weblogs.asp.net/adweigert/archive/2008/04/30/powershell-threading-enhancements-ftw.aspx</id><published>2008-04-30T13:11:00Z</published><updated>2008-04-30T13:11:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;To build on the threading library I mentioned &lt;A class="" title="PowerShell: Threading for PowerShell v1.0" href="http://weblogs.asp.net/adweigert/archive/2008/04/29/powershell-threading-for-powershell-v1-0.aspx" target=_blank mce_href="http://weblogs.asp.net/adweigert/archive/2008/04/29/powershell-threading-for-powershell-v1-0.aspx"&gt;here&lt;/A&gt;, I've added some functionality to make it easier to communicate with the seperate thread. Still, keep in mind that PowerShell will only allow one pipeline to be executing in a runspace at any given time. So, these new functions can only be used while the thread is inactive. But, they provide power into setting up the thread to be run and communicating with the original runspace.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The new functions are as follows:&lt;/P&gt;
&lt;P mce_keep="true"&gt;Get-ThreadVariable - Accesses available variables from within the thread.&lt;BR&gt;Set-ThreadVariable - Sets a variable for use within the thread.&lt;BR&gt;Invoke-ThreadExpression - Allows synchronous execution of a script block within the thread.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I also updated the Join-Thread function to include an optional -timeout parameter so that you could return control back if the thread didn't complete in the desired time. I also updated the Running property to IsRunning and changed it so that it will only return true while the asynchronous invoke command is executing.&lt;/P&gt;
&lt;P mce_keep="true"&gt;With this new example you can do even more now, as shown here.&lt;/P&gt;&lt;PRE mce_keep="true"&gt;$thread = New-Thread&lt;BR&gt;Invoke-ThreadExpression $thread { function foo($bar) { echo "$bar!" } }&lt;BR&gt;Set-ThreadVariable $thread "name" "PowerShell Rocks"&lt;BR&gt;Start-Thread -thread $thread { $value = foo $name } | Out-Null&lt;BR&gt;Join-Thread $thread&lt;BR&gt;Get-ThreadVariable $thread "value"&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;This should return "PowerShell Rocks!" when Get-ThreadVariable is called. I've already used this script to multi-thread our Exchange backup from a single script. It is working quite nicely (nice as in have cut our 8 hour backup down to 4 hours)&amp;nbsp;and I can already imagine several other wonderful places it will be used.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6144660" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /></entry><entry><title>PowerShell: Threading for PowerShell v1.0</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2008/04/29/powershell-threading-for-powershell-v1-0.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="841" href="http://weblogs.asp.net/adweigert/attachment/6141977.ashx" /><id>http://weblogs.asp.net/adweigert/archive/2008/04/29/powershell-threading-for-powershell-v1-0.aspx</id><published>2008-04-29T20:20:00Z</published><updated>2008-04-29T20:20:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;Ok, so this solution really isn't threading, but a neat way to get async scripts to run! The important thing to remember is that each "thread" is actually a PowerShell "runspace". Meaning, scripts run within the thread don't have access to objects or functions defined outside the thread. The script is composed of the following commands:&lt;/P&gt;
&lt;P mce_keep="true"&gt;New-Thread: Creates a new instance of a thread&lt;BR&gt;Start-Thread: Invokes an async execution of a script block&lt;BR&gt;Stop-Thread: Stops a thread from running if it is still executing&lt;BR&gt;Read-Thread: Reads all errors and output to the current runspace&lt;BR&gt;Join-Thread: Waits for the thread to complete and reads off the errors and output to the current runspace&lt;/P&gt;
&lt;P mce_keep="true"&gt;A simple example of how to use this is as follows.&lt;/P&gt;&lt;PRE mce_keep="true"&gt;$thread = Start-Thread {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($i in (1..5)) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Sleeping for $i seconds..."&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start-Sleep&amp;nbsp;$i&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/PRE&gt;&lt;PRE mce_keep="true"&gt;# ... do some work here or spawn other threads&lt;/PRE&gt;&lt;PRE mce_keep="true"&gt;Join-Thread $thread&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;I have some other ideas around injecting "variables" and being able to run script blocks within the new "thread" but I'll save that for a later post ...&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6141977" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /></entry><entry><title>Windows Server 2008 / Vista - Network Scalability "Feature"</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2008/03/15/windows-server-2008-vista-network-scalability-quot-feature-quot.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2008/03/15/windows-server-2008-vista-network-scalability-quot-feature-quot.aspx</id><published>2008-03-16T00:05:00Z</published><updated>2008-03-16T00:05:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;I highly recommend, if you are running Windows Server 2008 or Windows Vista, to disable the network scalability features. If you don't, you run the chance of one day running into "slow" performance of an application between one client or server and another. You will spend countless hours trying to debug why the network communication is so slow to that feature from that one client when it works fine for you and serveral others in the same area and with the same configuration. As far as I am concerned, TCP offloading has been a failure since the beginning, and I am not sure who is to blame, Microsoft or the hardware vendors. Oddly enough, I even saw the "symptoms" on a virtual server.&lt;/P&gt;
&lt;P mce_keep="true"&gt;From an Administrator command prompt:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&lt;FONT size=2&gt;netsh int tcp set global rss=disabled chimney=disabled autotuninglevel=disabled&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;Enjoy!&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5978476" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /><category term="Network Scaliblity" scheme="http://weblogs.asp.net/adweigert/archive/tags/Network+Scaliblity/default.aspx" /><category term="Windows Server 2008" scheme="http://weblogs.asp.net/adweigert/archive/tags/Windows+Server+2008/default.aspx" /><category term="Windows Vista" scheme="http://weblogs.asp.net/adweigert/archive/tags/Windows+Vista/default.aspx" /></entry><entry><title>C#: My First Lambda Expression</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2007/12/16/c-my-first-lamba-expression.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2007/12/16/c-my-first-lamba-expression.aspx</id><published>2007-12-16T12:56:00Z</published><updated>2007-12-16T12:56:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;I don't know about anyone else, but I found it annoying to have to put on&amp;nbsp;three-lines of code (or one ugly one-line of code) for an&amp;nbsp;IF statement for argument validation. Mostly, I want to check a simple condition and if true, throw an exception. Well, lambda to the rescue! I find the lambda version much more readable than a one-line IF statement, but that is just me -- mainly because I dislike one-line IF statements.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Another advantage of the lamba expression is that the "new Exception" is only created if the delegate is called when the condition is true. Who knows, maybe I'll change my mind on liking this after I have more experience with .NET 3.5, but for now I think this is very cool...&lt;/P&gt;
&lt;P mce_keep="true"&gt;I guess this will have to do until we have MACRO replacement in C# ... :)&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Lucida Console, Courier New, Courier, monospace"&gt;&lt;FONT color=#0000ff&gt;
&lt;P&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;delegate&lt;/FONT&gt; T &lt;/FONT&gt;&lt;FONT color=#2b91af&gt;CreateObjectDelegate&lt;/FONT&gt;&amp;lt;T&amp;gt;();&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;internal&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Validator&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; ThrowIf(&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;bool&lt;/FONT&gt; condition, &lt;/FONT&gt;&lt;FONT color=#2b91af&gt;CreateObjectDelegate&lt;/FONT&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;Exception&lt;/FONT&gt;&amp;gt; createObject)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (condition)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt; createObject();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;internal&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;Example&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; ShowName(&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; name)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#008000&gt;// LAMBA expression&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af&gt;Validator&lt;/FONT&gt;.ThrowIf(&lt;/FONT&gt;name.IsNullOrEmpty(), () =&amp;gt; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ArgumentException&lt;/FONT&gt;(&lt;/FONT&gt;&lt;FONT color=#a31515&gt;"The parameter is required."&lt;/FONT&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515&gt;"name"&lt;/FONT&gt;));&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#008000&gt;// IF statement&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; (&lt;/FONT&gt;name.IsNullOrEmpty()) &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;throw&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ArgumentException&lt;/FONT&gt;(&lt;/FONT&gt;&lt;FONT color=#a31515&gt;"The parameter is required."&lt;/FONT&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515&gt;"name"&lt;/FONT&gt;);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#2b91af&gt;Console&lt;/FONT&gt;.WriteLine(name);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5461335" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="c#" scheme="http://weblogs.asp.net/adweigert/archive/tags/c_2300_/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /><category term="Orcas" scheme="http://weblogs.asp.net/adweigert/archive/tags/Orcas/default.aspx" /></entry><entry><title>C#: My First Extension Method</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2007/12/08/c-my-first-extension-method.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2007/12/08/c-my-first-extension-method.aspx</id><published>2007-12-08T15:01:00Z</published><updated>2007-12-08T15:01:00Z</updated><content type="html">&lt;P&gt;I will find many, many uses for this ... maybe someone else will too! &lt;/P&gt;
&lt;P style="FONT-FAMILY: Lucida Console; Courier: "&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System;&lt;BR&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt; System.Diagnostics;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;internal&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;StringExtensions&lt;/FONT&gt;&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;public&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;static&lt;/FONT&gt; T ToEnum&amp;lt;T&amp;gt;(&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; value)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;where&lt;/FONT&gt; T : &lt;FONT color=#0000ff&gt;struct&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#2b91af&gt;Debug&lt;/FONT&gt;.Assert(!&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt;.IsNullOrEmpty(value));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; (T)&lt;FONT color=#2b91af&gt;Enum&lt;/FONT&gt;.Parse(&lt;FONT color=#0000ff&gt;typeof&lt;/FONT&gt;(T), value, &lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5422348" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="c#" scheme="http://weblogs.asp.net/adweigert/archive/tags/c_2300_/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /><category term="Orcas" scheme="http://weblogs.asp.net/adweigert/archive/tags/Orcas/default.aspx" /></entry><entry><title>PowerShell: Try...Catch...Finally Comes To Life</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx</id><published>2007-10-10T21:18:00Z</published><updated>2007-10-10T21:18:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;So, PowerShell has some good error handling, but being so used to .NET, I really missed my Try...Catch...Finally statements. Especially when I needed to make sure a block of code always executed. Well, after some playing, I think I have the solution! I've tested this function in a few different ways. I hope this turns out to be as helpful to someone else as it is for me. Maybe Microsoft will add this functionality&amp;nbsp;to the core of PowerShell.&lt;/P&gt;
&lt;BLOCKQUOTE style="FONT-FAMILY: courier,monospace"&gt;
&lt;P mce_keep="true"&gt;function Try&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ScriptBlock]$Command = $(throw "The parameter -Command is required."),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ScriptBlock]$Catch&amp;nbsp;&amp;nbsp; = { throw $_ },&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ScriptBlock]$Finally = {}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $local:ErrorActionPreference = "SilentlyContinue"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trap&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trap&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trap { throw $_ }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;$Finally&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw $_&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_ | &amp;amp; { &amp;amp;$Catch }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;$Command&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trap { throw $_ }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;$Finally&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;# Example usage&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Try {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo " ::Do some work..."&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo " ::Try divide by zero: $(0/0)"&lt;BR&gt;} -Catch {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "&amp;nbsp; ::Cannot handle the error (will rethrow): $_"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #throw $_&lt;BR&gt;} -Finally {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo " ::Cleanup resources..."&lt;BR&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4518796" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /></entry><entry><title>PowerShell: Using PowerShell to Debug .NET Class Libraries</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2007/08/20/powershell-using-powershell-to-debug-net-class-libraries.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2007/08/20/powershell-using-powershell-to-debug-net-class-libraries.aspx</id><published>2007-08-20T19:50:00Z</published><updated>2007-08-20T19:50:00Z</updated><content type="html">&lt;P&gt;PowerShell is so wicked cool. I love it more and more each day I use it. Latest trick is using it to debug or my class libraries without having to have a supporting unit test or console project.&lt;/P&gt;
&lt;P&gt;Though this method of testing / debuging process isn't as good as unit testing, it sure is handy for some small client utilities or where you just want to "try" something in one of your class libraries without changing all your unit tests.&lt;/P&gt;
&lt;P&gt;What you need to do is set your project to launch an external command and point it to your PowerShell installation, typically: &lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;The command line arguments for your debug external program should be: &lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;-NoExit -command "&amp;amp; { . .\Debug.ps1 }"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Then, add a file to your project called Debug.ps1, make sure you set it to copy to the output directory.&lt;/P&gt;
&lt;P&gt;When you run your class library in debug mode it will launch the PowerShell console and then execute the Debug.ps1 file. My file contains something like the following to load my assembly and a few functions to automate some of the things I might do while debugging. After this script runs, you will be left with a fully functioning PowerShell instance that you can use to further test your class library.&lt;/P&gt;
&lt;P&gt;Did I mention this is an awesome trick for building custom PowerShell commands? Well, I'm pretty sure it is, but I have not gotten that far, yet.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;#Debug.ps1&lt;BR&gt;[System.AppDomain]::CurrentDomain.AppendPrivatePath($PWD)&lt;BR&gt;[System.Reflection.Assembly]::LoadFrom("DotDeploy.dll")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;function global:New-DeploymentDefinition&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return New-Object DotDeploy.DeploymentDefinition&lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;function global:New-DeploymentCopyFileTask&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param (&amp;nbsp;[string]$sourcePath, [string]$destinationPath )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return New-Object DotDeploy.DeploymentCopyFileTask $source,$destination&lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;function global:New-DeploymentServer&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param ([string]$server, [int]$port)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return New-Object DotDeployt.DeploymentServer $server,$port&lt;BR&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'"&gt;$source = New-DeploymentServer "MARIO",9216&lt;BR&gt;$destination = New-DeploymentServer "LUIGI",9216&lt;BR&gt;$deployment = New-DeploymentDefinition&lt;BR&gt;$task = New-DeploymentCopyFileTask "C:\Program Files\DotDeploy\v1.0\Configuration" "C:\Program Files\DotDeploy\v1.0\Configuration"&lt;BR&gt;$task.Recursive = $true&lt;BR&gt;$task.InputFilter = "*.xml"&lt;BR&gt;$deployment.Tasks.Add($task)&lt;BR&gt;$deployment.Source = $source&lt;BR&gt;$deployment.Destination = $destination&lt;BR&gt;$destination.Lock()&lt;BR&gt;$deployment.Deploy()&lt;BR&gt;$destination.Unlock()&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Update Note: Make sure when you load your assembly you use &lt;STRONG&gt;LoadFrom&lt;/STRONG&gt;&amp;nbsp;and not &lt;STRONG&gt;LoadFile&lt;/STRONG&gt; becasue LoadFile will not resolve dependencies but LoadFrom does. You can also append a private path to the current AppDomain as shown (added)&amp;nbsp;in the example.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3568563" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /><category term="Debugging" scheme="http://weblogs.asp.net/adweigert/archive/tags/Debugging/default.aspx" /></entry><entry><title>PowerShell: Convert Active Directory IADSLargeInteger to System.Int64</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2007/03/23/powershell-convert-active-directory-iadslargeinteger-to-system-int64.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2007/03/23/powershell-convert-active-directory-iadslargeinteger-to-system-int64.aspx</id><published>2007-03-23T14:28:00Z</published><updated>2007-03-23T14:28:00Z</updated><content type="html">&lt;p&gt;This PowerShell function will convert an IADSLargeInteger ComObject to a long/Int64 value. Extremely helpful when trying to work with Active Directory attributes like &amp;quot;pwdLastSet&amp;quot; or &amp;quot;lastLogonTimestamp&amp;quot;.&lt;/p&gt;&lt;pre style="font-size: 90%"&gt;function ConvertADSLargeInteger([object] $adsLargeInteger)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; $highPart = $adsLargeInteger.GetType().InvokeMember(&amp;quot;HighPart&amp;quot;, [System.Reflection.BindingFlags]::GetProperty, $null, $adsLargeInteger, $null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; $lowPart&amp;nbsp; = $adsLargeInteger.GetType().InvokeMember(&amp;quot;LowPart&amp;quot;,&amp;nbsp; [System.Reflection.BindingFlags]::GetProperty, $null, $adsLargeInteger, $null)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $bytes = [System.BitConverter]::GetBytes($highPart)
&amp;nbsp;&amp;nbsp;&amp;nbsp; $tmp&amp;nbsp;&amp;nbsp; = [System.Byte[]]@(0,0,0,0,0,0,0,0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.Array]::Copy($bytes, 0, $tmp, 4, 4)
&amp;nbsp;&amp;nbsp;&amp;nbsp; $highPart = [System.BitConverter]::ToInt64($tmp, 0)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $bytes = [System.BitConverter]::GetBytes($lowPart)
&amp;nbsp;&amp;nbsp;&amp;nbsp; $lowPart = [System.BitConverter]::ToUInt32($bytes, 0)
&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $lowPart + $highPart
}&lt;/pre&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2083767" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="active directory" scheme="http://weblogs.asp.net/adweigert/archive/tags/active+directory/default.aspx" /><category term="powershell" scheme="http://weblogs.asp.net/adweigert/archive/tags/powershell/default.aspx" /><category term=".net" scheme="http://weblogs.asp.net/adweigert/archive/tags/.net/default.aspx" /></entry><entry><title>SqlViewState - The Path To Better ViewState Storage</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/adweigert/archive/2004/03/09/sqlviewstate-the-path-to-better-viewstate-storage.aspx" /><id>http://weblogs.asp.net/adweigert/archive/2004/03/09/sqlviewstate-the-path-to-better-viewstate-storage.aspx</id><published>2004-03-09T17:14:00Z</published><updated>2004-03-09T17:14:00Z</updated><content type="html">&lt;p&gt;A while ago, several colleges of mine were having a terrible time with the loading times of some pages of their web application. Come to find out, they were suffering from ViewState bloat. ViewState was something I always tried to stay away from in the past because of this factor. Sure, it was very helpful but I found ways around it.&lt;/p&gt;&lt;p&gt;However, I have come to a change of heart to realize ViewState is a wonderful thing, except that it can still cause pages to suffer from the ViewState bloat symptom. You could be a frugal programmer and control the ViewState more by only allowing certain pieces into but there are times when you want to store large amounts of data in the ViewState. For example, you may have search results that were very costly to find and you need to persist the results for paging.&lt;/p&gt;&lt;p&gt;So, I started looking at different devices to store the ViewState in. I thought of putting it into our session state which is stored in a SQL database, but the timeout settings for session and page view state were very different in some cases and this method would not allow for the flexibility that is required. Or perhaps someone avoids session state like the plague or it isn&amp;#39;t stored in a central repository in case of a web farm approach.&lt;/p&gt;&lt;p&gt;The decision was easy, I would create a small table that stores ViewState in it much like the session state. I actually put the table and procedures in the same database as our session state just for consistency. It was also easy to script the job that cleans up timed out ViewState since we already had one for the session state. Here is the install script you will need to run to setup the table, stored procedures, and job to clean up the table every so often.&lt;/p&gt;&lt;p&gt;&lt;a href="http://weblogs.asp.net/adweigert/archive/2005/07/11/419029.aspx" target="_blank"&gt;[Database Code]&lt;/a&gt;&lt;/p&gt;&lt;p&gt;To keep it simple I simply look for one value, the connection string to use in an appSetting key called &amp;ldquo;ViewStateConnectionString&amp;ldquo;. Optionally, you can define a &amp;ldquo;ViewStateTimeout&amp;ldquo; with a value being the number of minutes to wait before clearing the ViewState data. You can also set this value per page if you have certain pages that will live longer on the client before a post back. If the connection string is not provided, it will not affect the ViewState processing as it will resort to the old method. The following is an example of the appSettings section.&lt;/p&gt;&lt;p align="left" class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 9pt; color: blue; font-family: 'Lucida Console'"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size: 9pt; color: maroon; font-family: 'Lucida Console'"&gt;appSettings&lt;/span&gt;&lt;span style="font-size: 9pt; color: blue; font-family: 'Lucida Console'"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="left" class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 9pt; font-family: 'Lucida Console'"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;add&lt;/span&gt;&lt;span style="color: fuchsia"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ViewStateConnectionString&amp;quot;&lt;/span&gt;&lt;span style="color: fuchsia"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Server=(local);Database=ASPState;Trusted_Connection=yes;&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="left" class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 9pt; font-family: 'Lucida Console'"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;add&lt;/span&gt;&lt;span style="color: fuchsia"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ViewStateTimeout&amp;quot;&lt;/span&gt;&lt;span style="color: fuchsia"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;20&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="left" class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 9pt; color: blue; font-family: 'Lucida Console'"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size: 9pt; color: maroon; font-family: 'Lucida Console'"&gt;appSettings&lt;/span&gt;&lt;span style="font-size: 9pt; color: blue; font-family: 'Lucida Console'"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Here is the class that you will need to inherit from if you want to take advantage of this ViewState change, provided for you in the wonderful language of C#. I apologize for the lack of comments, hopefully it is self explanatory.&lt;/p&gt;&lt;p&gt;&lt;a href="http://weblogs.asp.net/adweigert/archive/2005/07/11/419030.aspx" target="_blank"&gt;[C# Code]&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=86628" width="1" height="1"&gt;</content><author><name>adweigert</name><uri>http://weblogs.asp.net/members/adweigert.aspx</uri></author><category term="c#" scheme="http://weblogs.asp.net/adweigert/archive/tags/c_2300_/default.aspx" /><category term="asp.net" scheme="http://weblogs.asp.net/adweigert/archive/tags/asp.net/default.aspx" /><category term="viewstate" scheme="http://weblogs.asp.net/adweigert/archive/tags/viewstate/default.aspx" /><category term="sql" scheme="http://weblogs.asp.net/adweigert/archive/tags/sql/default.aspx" /></entry></feed>