<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vallery.net &#187; MOSS</title>
	<atom:link href="http://vallery.net/tag/moss/feed/" rel="self" type="application/rss+xml" />
	<link>http://vallery.net</link>
	<description>personal homepage of Jason Vallery</description>
	<lastBuildDate>Sun, 05 Feb 2012 20:13:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Activating features in bulk on the MySite with PowerShell</title>
		<link>http://vallery.net/2010/04/01/activating-features-in-bulk-on-the-mysite-with-powershell/</link>
		<comments>http://vallery.net/2010/04/01/activating-features-in-bulk-on-the-mysite-with-powershell/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 01:42:46 +0000</pubDate>
		<dc:creator>jvallery</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Feature Activation]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://vallery.net/?p=178</guid>
		<description><![CDATA[I recently came across a client who needed to activate a couple of features on their MySites in batches.   Given that they have a significant number of MySites already created we needed to find a way to stage the deployment of the new functionality that the features offer.   I put together a PowerShell script that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a client who needed to activate a couple of features on their MySites in batches.   Given that they have a significant number of MySites already created we needed to find a way to stage the deployment of the new functionality that the features offer.   I put together a PowerShell script that iterates through the SSP looking for users who:</p>
<ul>
<li>Have a MySite</li>
<li>Either one of both of the required features are not currently active</li>
</ul>
<p>For each of the users that match the above criteria both of the features are activated.  A counter is incremented and once we reach the desired number of users for the batch the script exits.   When we are ready to process another batch the script effectively picks up where it left off since we&#8217;re skipping the users who are already activated.   </p>
<p>You could then have the execution of this script automatically executed on a regular basis during low utilization hours.  Eventually everyone will have the features activated and the new functionality deployed.   You could continue to let the script execute to catch any new users (if you decide not to staple the features like we are).</p>
<p>For others looking to do something similar I’m posting the original script in its entirety.</p>
<pre>
<span style="color: #000000;">
</span><span style="color: #008000;">#</span><span style="color: #008000;">##########################</span><span style="color: #008000;">
#</span><span style="color: #008000;"> "Configure Settings"</span><span style="color: #008000;">
</span><span style="color: #800080;">$SSPName</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">SSPAdmin</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$mysiteurl</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">http://mysite</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$ngsite_feature_id</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">6a91335c-5ecc-4afc-aa68-14d73afbb1bc</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$webpart_feature_id</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">5174F049-99D9-4d68-96E0-93AB2AE1C7BC</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$userCount</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">500</span><span style="color: #000000;">
</span><span style="color: #800080;">$stsadm</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$env:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #008000;">#</span><span style="color: #008000;">##########################</span><span style="color: #008000;">
</span><span style="color: #000000;">
</span><span style="color: #008000;">#</span><span style="color: #008000;">Load the SharePoint Assemblies</span><span style="color: #008000;">
</span><span style="color: #000000;">[</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">LoadWithPartialName</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">Microsoft.Office.Server</span><span style="color: #800000;">"</span><span style="color: #000000;">)
[</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">LoadWithPartialName</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">Microsoft.Office.Server.UserProfiles</span><span style="color: #800000;">"</span><span style="color: #000000;">)

</span><span style="color: #008000;">#</span><span style="color: #008000;">Create the SSP objects</span><span style="color: #008000;">
</span><span style="color: #800080;">$ServerContext</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> [Microsoft.Office.Server.ServerContext]::GetContext(</span><span style="color: #800080;">$SSPName</span><span style="color: #000000;">);
</span><span style="color: #800080;">$UPManager</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> new-object Microsoft.Office.Server.UserProfiles.UserProfileManager(</span><span style="color: #800080;">$ServerContext</span><span style="color: #000000;">);

</span><span style="color: #800080;">$enumProfiles</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$UPManager</span><span style="color: #000000;">.GetEnumerator();
</span><span style="color: #800000;">"</span><span style="color: #800000;">Total User Profiles available:</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$UPManager</span><span style="color: #000000;">.Count
</span><span style="color: #800080;">$count</span><span style="color: #FF0000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;

</span><span style="color: #008000;">#</span><span style="color: #008000;">Loop through every user who has an entry in the SSP</span><span style="color: #008000;">
</span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$oUser</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$enumProfiles</span><span style="color: #000000;">)
{
    </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the username for the user</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$u</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$oUser</span><span style="color: #000000;">.Item(</span><span style="color: #800000;">"</span><span style="color: #800000;">Accountname</span><span style="color: #800000;">"</span><span style="color: #000000;">)

    </span><span style="color: #008000;">#</span><span style="color: #008000;">How many have we activated?  If more than $userCount above stop processing</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$count</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-ge</span><span style="color: #000000;"> </span><span style="color: #800080;">$userCount</span><span style="color: #000000;">) {
        Write-Output </span><span style="color: #800000;">"</span><span style="color: #800000;">Okay, we're stopping for now because we've activated for $userCount MySites</span><span style="color: #800000;">"</span><span style="color: #000000;">
        </span><span style="color: #0000FF;">break</span><span style="color: #000000;">
    } </span><span style="color: #0000FF;">else</span><span style="color: #000000;"> {

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Does the user have a MySite?  If so continue</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$oUser</span><span style="color: #000000;">[</span><span style="color: #800000;">'</span><span style="color: #800000;">PersonalSpace</span><span style="color: #800000;">'</span><span style="color: #000000;">].Value </span><span style="color: #FF0000;">-ne</span><span style="color: #000000;"> </span><span style="color: #800080;">$null</span><span style="color: #000000;">) {
        </span><span style="color: #008000;">#</span><span style="color: #008000;">Create an SPSite (Site Collection) and SPWeb (Web) object for the given users MySite</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #800080;">$siteurl</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$mysiteurl</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$oUser</span><span style="color: #000000;">[</span><span style="color: #800000;">'</span><span style="color: #800000;">PersonalSpace</span><span style="color: #800000;">'</span><span style="color: #000000;">].Value
        </span><span style="color: #800080;">$spSite</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> new-object Microsoft.SharePoint.SPSite(</span><span style="color: #800080;">$siteurl</span><span style="color: #000000;">)
        </span><span style="color: #800080;">$spWeb</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$spSite</span><span style="color: #000000;">.OpenWeb() 

        </span><span style="color: #008000;">#</span><span style="color: #008000;">Let's check to see if either of the features we want to activate are currently activated.  </span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #008000;">#</span><span style="color: #008000;">If not we should activate them.   Remember that the NewsGator Site Feature is "site" scoped thus we use SPWeb</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #008000;">#</span><span style="color: #008000;">The web part feature is Site Collection scoped so we have to use SPSite</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> ((</span><span style="color: #800080;">$spWeb</span><span style="color: #000000;">.Features[</span><span style="color: #800080;">$ngsite_feature_id</span><span style="color: #000000;">] </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$null</span><span style="color: #000000;">) </span><span style="color: #FF0000;">-or</span><span style="color: #000000;"> (</span><span style="color: #800080;">$spSite</span><span style="color: #000000;">.Features[</span><span style="color: #800080;">$webpart_feature_id</span><span style="color: #000000;">] </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$null</span><span style="color: #000000;">)) {

            </span><span style="color: #008000;">#</span><span style="color: #008000;">Execute STSADM -o activatefeature to activate the NewsGator Site Feature for this user, if it fails capture that and stop execution of the program.</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$sResult</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> &amp;stsadm -o activatefeature -id </span><span style="color: #800080;">$ngsite_feature_id</span><span style="color: #000000;"> -force -url  </span><span style="color: #800080;">$siteurl</span><span style="color: #000000;">
            </span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #FF0000;">!</span><span style="color: #000000;">(</span><span style="color: #800080;">$sResult</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-like</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">*Operation completed successfully*</span><span style="color: #800000;">"</span><span style="color: #000000;">)){
                Write-Host -ForegroundColor </span><span style="color: #800000;">"</span><span style="color: #800000;">red</span><span style="color: #800000;">"</span><span style="color: #000000;"> -BackgroundColor </span><span style="color: #800000;">"</span><span style="color: #800000;">white</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Activate of site upgrade feature failed for $u on $siteurl : `n $sResult</span><span style="color: #800000;">"</span><span style="color: #000000;">
                </span><span style="color: #0000FF;">break</span><span style="color: #000000;">
            }

            </span><span style="color: #008000;">#</span><span style="color: #008000;">Execute STSADM -o activatefeature to activate the Webpart deployment feature, if it fails capture that and stop execution</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$sResult</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> &amp;stsadm -o activatefeature -id </span><span style="color: #800080;">$webpart_feature_id</span><span style="color: #000000;"> -force -url  </span><span style="color: #800080;">$siteurl</span><span style="color: #000000;">
            </span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #FF0000;">!</span><span style="color: #000000;">(</span><span style="color: #800080;">$sResult</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-like</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">*Operation completed successfully*</span><span style="color: #800000;">"</span><span style="color: #000000;">)){
                Write-Host -ForegroundColor </span><span style="color: #800000;">"</span><span style="color: #800000;">red</span><span style="color: #800000;">"</span><span style="color: #000000;"> -BackgroundColor </span><span style="color: #800000;">"</span><span style="color: #800000;">white</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Activate of mysite web parts feature failed for $u on $siteurl : `n $sResult</span><span style="color: #800000;">"</span><span style="color: #000000;">
                </span><span style="color: #0000FF;">break</span><span style="color: #000000;">
            }

            </span><span style="color: #008000;">#</span><span style="color: #008000;">increment the count and output a status</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$count</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$count</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;
            Write-Output </span><span style="color: #800000;">"</span><span style="color: #800000;">($count):  Features activated on $siteurl for $u succesfully</span><span style="color: #800000;">"</span><span style="color: #000000;">;
        } </span><span style="color: #0000FF;">else</span><span style="color: #000000;"> {
            Write-Output </span><span style="color: #800000;">"</span><span style="color: #800000;">Skipping $siteurl for $u as they are already active.</span><span style="color: #800000;">"</span><span style="color: #000000;">
        }
    } </span><span style="color: #0000FF;">else</span><span style="color: #000000;"> {
        Write-Output </span><span style="color: #800000;">"</span><span style="color: #800000;">Skipping $siteurl for $u as they do not have a MySite.</span><span style="color: #800000;">"</span><span style="color: #000000;">
    }

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Clean up our objects to prevent a memory leak</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$spWeb</span><span style="color: #000000;">.Dispose();
    </span><span style="color: #800080;">$spSite</span><span style="color: #000000;">.Dispose();
    </span><span style="color: #800080;">$siteurl</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$null</span><span style="color: #000000;">;
    }
} 

</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://vallery.net/2010/04/01/activating-features-in-bulk-on-the-mysite-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

