Custom SharePoint Alert Filter

I am always looking for ways to make things work the way you REALLY want them to.  Take the alerts in SharePoint as an example.  Wouldn’t it be great to say “only alert me when this criteria is met”.  Most of you are probably thinking that is as easy as a workflow, right?  Well what if you really want to test the BEFORE and AFTER values of a field to make sure.  Hmm…that might mean a custom workflow.  New solution, look at the SPAlert object and look at SQL to see how this baby really works.

You ever looked at what happens after you go to a list and sign up to receive something that you didn’t change?  If you see the CAML query that SharePoint generates, you might be asking yourself “what is this?”.  The FieldRef points to a “Editor/New” column.  What the heck?  That doesn’t exist anywhere.  Then again, Editor does, but what is this “New” thing?  Look at some other types and you will see the “Editor/Old” popping up.  Getting where I am headed?  You know the SPAlert.Filter property has a get; and a set;, right?  Hmmmmm…let your imagination do the rest.  Create the SPAlert manually, or script it…you will like it.

$alert = $web.AllUsers["domain\kirkhofer"].Alerts.Add();
$alert.Filter = "<Query><Neq><FieldRef Name="_Status/Old"/><FieldRef Name="_Status/New"/></Neq></Query>";
$alert.List = $list;
$alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List;
$alert.Title = "Status Change";
$alert.EventType = [Microsoft.SharePoint.SPEventType]::Modify;
$alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate;
$alert.Update($false);

Move MOSS Web To WSS

Ever try to import a web from a MOSS server to a WSS server and get those little errors about “Could not find feature xxxx”.  More specifically, the first one you run in to is “Could not find feature OffWFCommon”.  Here is a little trick to get rid of those before you migrate.

$siteurl = "http://blah"
$site = new-object Microsoft.SharePoint.SPSite $siteurl
$web = $site.OpenWeb()

stsadm -o deactivatefeature -url $siteurl -name OffWFCommon
stsadm -o deactivatefeature -url $siteurl -name TranslationWorkflow

$site.features|%{$_.Definition}|?{$_.ReceiverAssembly -like "*Office*"}|select DisplayName
$site.features|%{$_.Definition}|?{$_.ReceiverAssembly -like "*Office*"}|%{stsadm -o deactivatefeature -url $site.url -name $_.DisplayName}

stsadm -o deactivatefeature -url $siteurl -name TransMgmtLib

$web.features|%{$_.Definition}|select displayname,status

SharePoint Warm Up Script

I have had a lot of people use my other warm up script that I created almost a year ago but several people have asked for one that actually works…doh.  You see, my old one just used the WebRequest object to hit the site.  That does NOT warm up the site.  You actually need to get content from the page first.

This new script is a complete one that can be scheduled on your WFEs.  If you didn’t know already, all the Application Pools that get created are scheduled to reset themselves at a certain time.  Usually around 2 AM in the morning.  So if you want, take this script and put it in a CMD or BAT file and put an IISRESET right in front of it.  Then, add the code I have provided in a PS1 script and you are off and gunning.  You can remove those app pool recycles that are scheduled.

Save the following in a script named SPWarmUp.ps1

############################################################################
#Assumptions:
#-Running on machine with WSS/MOSS
#-C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN in path
############################################################################
function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
{
$wc = new-object net.webclient
if($cred -eq $null)
{
$cred = [System.Net.CredentialCache]::DefaultCredentials;
}
$wc.credentials = $cred;
return $wc.DownloadString($url);
}

#This passes in the default credentials needed. If you need specific stuff you can use something else to
#elevate basically the permissions. Or run this task as a user that has a Policy above all the Web Applications
#with the correct permissions
$cred = [System.Net.CredentialCache]::DefaultCredentials;
#$cred = new-object System.Net.NetworkCredential("username","password","machinename")

[xml]$x=stsadm -o enumzoneurls
foreach ($zone in $x.ZoneUrls.Collection) {
    [xml]$sites=stsadm -o enumsites -url $zone.Default;
    foreach ($site in $sites.Sites.Site) {
        write-host $site.Url;
        $html=get-webpage -url $site.Url -cred $cred;
    }
}

When you schedule this to run through a scheduled task, make sure the user running this has the correct credentials on the sites being hit.  Obviously, make sure this is on ALL WFEs.

Can you test this without all the other stuff?  Sure, just copy and paste the code and put it in to PowerShell and give it a whirl.

Download the file here