• PowerShell: foreach with a first and last item number

    I wanted to work through 1000+ items in a PowerShell foreach loop, but I wanted to do it X at a time. I figured out the following foreach syntax to loop through all items after first and before last:

    $First = 15
    $Last = 45
    foreach ($Row in $Rows | select -first $Last | select -last (($Last - $First)+1)){
    . . . .
    }
    

  • Knockout alternate formattting

    I was using KnockoutJS to loop through and display some data. I wanted to apply some alternate formatting on every other row. I used this syntax containing the MOD operation to achieve the formatting I wanted.

    <!-- ko if: $index() % 2 === 0 -->
    

    The other thing I learned was that $index() is observable, so I can +1 it? I believe that is right.

    The following were some sources that clued me in:

    http://jsfiddle.net/KuJBv/11/
    https://groups.google.com/forum/#!msg/knockoutjs/ElVix0ksXh8/awkTFYewitAJ


  • Using PowerShell to add a Contact to a CRM 2011 MarketingList (SOAP)

    We had a user delete a Marketing List. I needed to recreate it. I went to a database backup and found the GUID of the deleted list.
    Then I used the following SQL query to find the GUIDs of all the members of that list:

    SELECT FullName
        ,ParentCustomerIdName
        ,[EntityId]
        ,[ListId]
        ,[ListMemberId]
      FROM [CRMDataBaseName].[dbo].[ListMember],[CRMDataBaseName].[dbo].Contact
      where ListId = '787b77ca-c47d-431b-863e-12a98969b097' AND 
      [EntityId] = ContactId
      order by LastName,FirstName
    

    I saved the EntityId column to a text file, and then I used the following PowerShell code to loop through the GUIDs and add them to a new MarketingList

    
    $ListMembers = Get-Content C:\IT\Temp\ListMemberGUIDs.txt
    foreach ($EntityId in $ListMembers){
    $xml = ""
    $xml += "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>";
    $xml += "  <s:Body>";
    $xml += "    <Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>";
    $xml += "      <request i:type='b:AddMemberListRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'>";
    $xml += "        <a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>";
    $xml += "          <a:KeyValuePairOfstringanyType>";
    $xml += "            <c:key>ListId</c:key>";
    $xml += "            <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>5deb4efb-4ed7-47f3-8e8e-bb487e0db423</c:value>";
    $xml += "          </a:KeyValuePairOfstringanyType>";
    $xml += "          <a:KeyValuePairOfstringanyType>";
    $xml += "            <c:key>EntityId</c:key>";
    $xml += "            <c:value i:type='d:guid' xmlns:d='http://schemas.microsoft.com/2003/10/Serialization/'>$($EntityId)</c:value>";
    $xml += "          </a:KeyValuePairOfstringanyType>";
    $xml += "        </a:Parameters>";
    $xml += "        <a:RequestId i:nil='true' />";
    $xml += "        <a:RequestName>AddMemberList</a:RequestName>";
    $xml += "      </request>";
    $xml += "    </Execute>";
    $xml += "  </s:Body>";
    $xml += "</s:Envelope>";
     
    $url="http://crm.sardverb.com/SardVerbinnen/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($xml)
    }
    
    
    

  • I am at SharePoint Conference 2012 !!! #SPC12

    I can’t wait for the sessions to start. Although seeing all these smart people is a little intimidating.

    20121112-082054.jpg


  • PowerShell script to backup all SharePoint 2010 lists in all webs in all sites

    More backups the better. I wanted a file level backup of every list. Below I used PowerShell to iterate through all the lists on the server and dump them into a folder

    $backupDir="c:\Temp"
    foreach ($web in $(Get-SPSite | Get-SPWeb)){
    	foreach ($list in $web.Lists) {
    	mkdir -force "$backupDir\$($Web.Title.replace(' ',''))\"
    	Export-SPWeb $($web.Url) -itemurl "$($list.RootFolder.ServerRelativeUrl)" -path "$backupDir\$($Web.Title.replace(' ',''))\$($list.Title.replace(' ','')).cmp"
    	}
    }
    

  • Install-SPSolution, Add-SPSolution and Update-SPSolution return error: not supported with version 4.0.30319.269 of the Microsoft .Net Runtime.

    Just tried to install a soliution, and I received the error:

    Install-SPSolution : Microsoft SharePoint is not supported with version 4.0.30319.269 of the Microsoft .Net Runtime.

    I just installed the new PowerShell 3.0. To fix, launch a new powershell with -Version 2, and then run your command again:

    powershell -version 2

    That is what I get for installing the newest and the greatest!


  • How to find the pid of your SharePoint site in Windows server 2008 (for Visual Studio attaching to w3wp.exe)

    C:\Windows\system32\inetsrv\appcmd.exe list wp


  • My git notes

    Been playing around with git to manage my “Environment”. This is a note to self. May add more at some point
    List files that have been “staged”
    • git diff –name-only –cached
    To create a “Centro repo”
    • To setup an empty central repo:
      • mkdir /your/path/folder/project.git
      • cd /your/path/folder/project.git
      • git init –bare –shared
    • To add files to the central repo:
      • Go to the existing file structure and setup a new git repo (if it is not there already)
      • cd your/local/workspace/project
      • git init
      • git add .
      • git commit -m “First Commit”
      • git remote add origin server.domain.com:/your/path/folder/project.git
      • git push origin master
    • If you make a change  in your local copy and you want to push it up to the Centro repo
      • git add .
      • git commit -m “This is what changed”
      • git push origin master
    • And to get those changes to other machines
      • git pull origin master
    • And to setup a new machine
      • git clone server.domain.com:/your/path/folder/project.git

    Got most of the info from here