• RSS feed for a vBulletin forum

    I am constantly having to look this up. What is a vBulletin’s form’s rss feed?

    http://www.myforum.com/external.php?type=rss&forumids=1

    Obviously the admin has to enable it. Have not tested against all versions

     


  • Server ran out of space and not accepting connections after freeing up space

    I was away on vacation, and a dev box ran out of space. Once I got back, I cleaned it up, rebooted and still could not connect to it. @xrobx99 noticed an IPSec message in the event logs:

    The IPSec driver has entered Block mode. IPSec will discard all inbound and outbound TCP/IP network traffic that is not permitted by boot-time IPSec Policy exemptions.

    We thought that was suspect as we weren’t using IPSec policies. It seems that our server ran out of space and the IPSec policy became corrupted.

    I ran the command :

    regsvr32 polstore.dll

    This command rebuilds the local policy store. I rebooted and all was fine.

    Hope that helps someone.


  • How to add custom JavaScript code to all SharePoint 2010 pages (DelegateControl)

    As I said in this post, there are plenty of articles on how to do this. This is more of a note for myself, as I have to “re-learn” this every time I need to customize SharePoint.

    There are 2 ways (that I know of) that you can add code to every page in SharePoint 2010, 1 by the AdditionalPageHead delegate control, or ,2 by Custom Action. This article is about #1 (see #2 here) using the AdditionalPageHead delegate control.

    • Start Visual Studio, and create a new Empty SharePoint Project (uncheck the Create Directory for Solution because you salways create the destination directory yourself)
    • Deploy as a Farm Solution (I have not figured what you can and can’t do with sandboxed solutions yet)
    • RightClick the Project and Add –> New item –> User Control –Name it. This will create a new folder named ControlTemplates and inside will be your User Control. Looks like this

    • Edit the new ascx file and add the code you want to put at the top of every page, for example:
    <script type="text/javascript" src="/path/to/jquery.js"></script>
    
    • RightCLick the Project and select Add Empty Element and name it at the bottom
    • add the following to the elements.xml file. The final should look like this below:
      <Control Id="AdditionalPageHead"
              Sequence="90"
              ControlSrc="~/_CONTROLTEMPLATES/DelegateControl/DelegateControl.ascx" />
    

    Package everything up and you will now see your reference to jQuery on the top of all pages.


  • ‘b’ is null or not an object

    This is a reminder to my self that this blog post has the solutoin to the “b” error when working with the Client Object Model. Basically I need to change this:

    createDelegate(this, this.onSuccessMethod)

    to this:

    createDelegate(this, onSuccessMethod)


  • Move the “Add new item” to the top of a list page in SharePoint 2010

    We did not like how SharePoint 2010’s “Add new item” was on the bottom of the page. we wanted to move it to the top. The following jQuery code moves it to the top of the page:

    $(“#s4-mainarea”).prepend($(“td.ms-addnew”))

    hope that helps someone.


  • PowerShell script to set the State of a record in Microsoft CRM 2011 (SOAP)

    I wanted to mark a meeting/appointment as completed via code. I came up with the PowerShell script below. Maybe it will be of use to some one?

    
    FUNCTION JBM-CRM-SetState {
    PARAM(
        [string][ValidateSet("crmserver.company.com", "dev-crmserver.company.com")]$ServerName="crm.sardverb.com",
        [string][ValidateSet("CRMOrganizationName")]$OrganizationName="SardVerbinnen",
        [string][parameter(Mandatory=$true)][ValidateSet("email", "phonecall", "appointment")]$EntityType,
        [string][parameter(Mandatory=$true)][ValidateScript({ $_ -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")})]$TargetGUID,
        $State=1,$Status=3,[switch]$MyDebug
        )
    $requestMain = ""
    $requestMain += "<s:Envelope xmlns:s=`"http://schemas.xmlsoap.org/soap/envelope/`">";
    $requestMain += "  <s:Body>";
    $requestMain += "    <Execute xmlns=`"http://schemas.microsoft.com/xrm/2011/Contracts/Services`" xmlns:i=`"http://www.w3.org/2001/XMLSchema-instance`">";
    $requestMain += "      <request i:type=`"b:SetStateRequest`" xmlns:a=`"http://schemas.microsoft.com/xrm/2011/Contracts`" xmlns:b=`"http://schemas.microsoft.com/crm/2011/Contracts`">";
    $requestMain += "        <a:Parameters xmlns:c=`"http://schemas.datacontract.org/2004/07/System.Collections.Generic`">";
    $requestMain += "          <a:KeyValuePairOfstringanyType>";
    $requestMain += "            <c:key>EntityMoniker</c:key>";
    $requestMain += "            <c:value i:type=`"a:EntityReference`">";
    $requestMain += "              <a:Id>$TargetGUID</a:Id>";
    $requestMain += "              <a:LogicalName>$EntityType</a:LogicalName>";
    $requestMain += "              <a:Name i:nil=`"true`" />";
    $requestMain += "            </c:value>";
    $requestMain += "          </a:KeyValuePairOfstringanyType>";
    $requestMain += "          <a:KeyValuePairOfstringanyType>";
    $requestMain += "            <c:key>State</c:key>";
    $requestMain += "            <c:value i:type=`"a:OptionSetValue`">";
    $requestMain += "              <a:Value>$State</a:Value>";
    $requestMain += "            </c:value>";
    $requestMain += "          </a:KeyValuePairOfstringanyType>";
    $requestMain += "          <a:KeyValuePairOfstringanyType>";
    $requestMain += "            <c:key>Status</c:key>";
    $requestMain += "            <c:value i:type=`"a:OptionSetValue`">";
    $requestMain += "              <a:Value>$Status</a:Value>";
    $requestMain += "            </c:value>";
    $requestMain += "          </a:KeyValuePairOfstringanyType>";
    $requestMain += "        </a:Parameters>";
    $requestMain += "        <a:RequestId i:nil=`"true`" />";
    $requestMain += "        <a:RequestName>SetState</a:RequestName>";
    $requestMain += "      </request>";
    $requestMain += "    </Execute>";
    $requestMain += "  </s:Body>";
    $requestMain += "</s:Envelope>";
    if ($MyDebug){write-host $requestMain}
    
    $url="http://$ServerName/$OrganizationName/XRMServices/2011/Organization.svc/web"
    
    $http_request = New-Object -ComObject Msxml2.XMLHTTP
    $http_request.Open('POST', $url, $false)
    $http_request.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    $http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    $http_request.setRequestHeader("Content-Length", $xml.length);
    $http_request.send($requestMain);
    if ($MyDebug){$http_request.responseText}
    }
    
    

  • BASH, cURL script to retrieve Google Analytics data

    Last week I wrote this PowerShell code to retrieve Google Analytics data. Below is similar code in BASH using the cURL command.

    #!/bin/bash
    stty -echo
    read -p "Password: " password; echo
    stty echo
    RESULT=$(curl -s https://www.google.com/accounts/ClientLogin \
    --data-urlencode [email protected] --data-urlencode Passwd=$password \
    -d accountType=GOOGLE \
    -d source=YourSource \
    -d service=analytics)
    
    
    AUTH=$(echo "$RESULT" | grep 'Auth=' | sed  s/Auth=//)
    
    curl -s "https://www.google.com/analytics/feeds/data?ids=ga%3AXXXXXXXX&metrics=ga%3Avisits&start-date=2012-05-01&end-date=2012-05-31&max-results=50" \
    --request GET --header "Authorization: GoogleLogin auth=$AUTH"
    
    #Done
    

  • Use PowerShell to get Google Analytics data

    I wanted to write a powershell script that will retrieve the number of visits for my site. I put the following script together. Note this uses Google’s ClientLogin for authentication, which is deprecated. I have not worked with OAuth 2 yet.

    
    function JBM-GA-GetStats {
    PARAM([string][ValidateSet("CurrentMonth","LastMonth","Today","Yesterday")]$Range="CurrentMonth",
            $GAId="XXXXXXXX",$email="[email protected]",[switch]$MyDebug)
    
    [datetime]$Today=[datetime]::Today
    [datetime]$Yesterday=[datetime]::Today.AddDays(-1)
    [datetime]$FirstDayCurrentMonth=$Today.AddDays(- ($Today.Day - 1))
    [datetime]$FirstDayPreviousMonth=$FirstDayCurrentMonth.AddMonths(-1)
    [datetime]$LastDayPreviousMonth=$FirstDayCurrentMonth.AddDays(-1)
    
    switch ($Range){
        "CurrentMonth" {
            $startdate=$FirstDayCurrentMonth.ToString("yyyy-MM-dd")
            $enddate=$Today.ToString("yyyy-MM-dd")
        }
        "LastMonth" {
            $startdate=$FirstDayPreviousMonth.ToString("yyyy-MM-dd")
            $enddate=$LastDayPreviousMonth.ToString("yyyy-MM-dd")        
        }
        "Today" {
            $startdate=$Today.ToString("yyyy-MM-dd")
            $enddate=$Today.ToString("yyyy-MM-dd")   
        }
        "Yesterday"{
            $startdate=$Yesterday.ToString("yyyy-MM-dd")
            $enddate=$Yesterday.ToString("yyyy-MM-dd")   
        }
    }
    
    $pw = read-host "Please Enter Your Password" -AsSecureString
    
    $null = [Reflection.Assembly]::LoadWithPartialName("System.Web")   
    $password= "Passwd=$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw)))"
    
    #getting my auth token
    $url="https://www.google.com/accounts/ClientLogin?Email=$($email)&$($password)&accountType=GOOGLE&source=mysource&service=analytics"
    if ($MyDebug){write-host $url}
    $webclient = new-object System.Net.WebClient
    $dataString=$webclient.DownloadString($url)
    $Auth=$dataString.split("`n")[2].split("=")[1]
    if ($MyDebug){write-host $Auth}
    
    #Connecting using auth token to get my data
    $webclient.Headers.Add("Authorization", "GoogleLogin auth=$($Auth)")
    $url="https://www.google.com/analytics/feeds/data?ids=ga%3A$($GAId)&metrics=ga%3Avisits&start-date=$($startdate)&end-date=$($enddate)&max-results=50"
    if ($MyDebug){write-host $url}
    [xml]$results=$webclient.DownloadString($url)
    
    write-host ("$($Range)'s $($results.feed.entry.metric.name): $($results.feed.entry.metric.value)")
    }