<?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; SharePoint 2007</title>
	<atom:link href="http://vallery.net/category/sharepoint-2007/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>Using PowerShell and the DirectorySearcher class</title>
		<link>http://vallery.net/2010/04/09/using-powershell-and-the-directorysearched-class/</link>
		<comments>http://vallery.net/2010/04/09/using-powershell-and-the-directorysearched-class/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 22:34:41 +0000</pubDate>
		<dc:creator>jvallery</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://vallery.net/?p=206</guid>
		<description><![CDATA[I needed to locate the LDAP distinguished name of an individual user account in a remote domain via PowerShell.   Assuming your script is running on a box that is part of a domain that has a trust to the remote domain we can do this by running a query against Active Directory with LDAP. By [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to locate the LDAP distinguished name of an individual user account in a remote domain via PowerShell.   Assuming your script is running on a box that is part of a domain that has a trust to the remote domain we can do this by running a query against Active Directory with LDAP.</p>
<p>By using the DirectorySearcher class we can build complex LDAP queries to find objects in Active Directory.   With this information you can do all kinds of fun scripting things.</p>
<p>Here is a sample script:</p>
<pre><span style="color: #000000;">

</span><span style="color: #008000;">#</span><span style="color: #008000;">Specify the search criteria</span><span style="color: #008000;">
</span><span style="color: #800080;">$samname</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;">jasonv</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$domain</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;">dev.lcl</span><span style="color: #800000;">"</span><span style="color: #000000;">

</span><span style="color: #008000;">#</span><span style="color: #008000;">Get a list of domains in the forest and grab the DN of the one matching the above parameter.</span><span style="color: #008000;">
</span><span style="color: #800080;">$forest</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> [</span><span style="color: #008080;">System.DirectoryServices.ActiveDirectory.Forest</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">GetCurrentForest</span><span style="color: #000000;">()
</span><span style="color: #800080;">$domain</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$forest</span><span style="color: #000000;">.Domains | ? {</span><span style="color: #800080;">$_</span><span style="color: #000000;">.Name </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$domain</span><span style="color: #000000;">}
</span><span style="color: #800080;">$domainDN</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$domain</span><span style="color: #000000;">.</span><span style="color: #8B4513;">GetDirectoryEntry</span><span style="color: #000000;">().distinguishedName
</span><span style="color: #5F9EA0; font-weight: bold;">Write-Output</span><span style="color: #000000;">  </span><span style="color: #800000;">"</span><span style="color: #800000;">Found the remote domain, the full LDAP distinguished name is $DomainDN</span><span style="color: #800000;">"</span><span style="color: #000000;">

</span><span style="color: #008000;">#</span><span style="color: #008000;">Create an LDAP searcher object and pass in the DN of the domain we wish to query</span><span style="color: #008000;">
</span><span style="color: #800080;">$Searcher</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">New-Object</span><span style="color: #000000;"> </span><span style="color: #800000;">System.DirectoryServices.DirectorySearcher</span><span style="color: #000000;">([</span><span style="color: #008080;">ADSI</span><span style="color: #000000;">]</span><span style="color: #800000;">"</span><span style="color: #800000;">LDAP://$domainDN</span><span style="color: #800000;">"</span><span style="color: #000000;">)

</span><span style="color: #008000;">#</span><span style="color: #008000;">Pass in the ceriteria we are searching for.</span><span style="color: #008000;">
#</span><span style="color: #008000;">In this case we're looking for users with a particular SAM name.</span><span style="color: #008000;">
</span><span style="color: #800080;">$Searcher</span><span style="color: #000000;">.</span><span style="color: #8B4513;">filter</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;">(&amp;(objectCategory=person)(objectClass=user)(sAMAccountName= $samname))</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$results</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$Searcher</span><span style="color: #000000;">.</span><span style="color: #8B4513;">Findall</span><span style="color: #000000;">()

</span><span style="color: #008000;">#</span><span style="color: #008000;">Loop through the results</span><span style="color: #008000;">
</span><span style="color: #0000FF;">Foreach</span><span style="color: #000000;">(</span><span style="color: #800080;">$result</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$results</span><span style="color: #000000;">){
    </span><span style="color: #800080;">$User</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$result</span><span style="color: #000000;">.</span><span style="color: #8B4513;">GetDirectoryEntry</span><span style="color: #000000;">()
    </span><span style="color: #800080;">$userDN</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;">  </span><span style="color: #800080;">$user</span><span style="color: #000000;">.</span><span style="color: #8B4513;">DistinguishedName</span><span style="color: #000000;">
    </span><span style="color: #5F9EA0; font-weight: bold;">Write-Output</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Found a user matching with the distingused name of $userDN</span><span style="color: #800000;">"</span><span style="color: #000000;">
}

</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://vallery.net/2010/04/09/using-powershell-and-the-directorysearched-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using powershell to set SSP profile properties</title>
		<link>http://vallery.net/2010/04/01/using-powershell-to-set-ssp-profile-properties/</link>
		<comments>http://vallery.net/2010/04/01/using-powershell-to-set-ssp-profile-properties/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 13:57:39 +0000</pubDate>
		<dc:creator>jvallery</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SSP]]></category>

		<guid isPermaLink="false">http://vallery.net/?p=180</guid>
		<description><![CDATA[I recently put together a powershell script that can be used to update a profile property of all of the users stored in the SharePoint SSP.  At NewsGator we use a boolean property field to indicate if a particular part of our product has been activated or not.  There are some cases where this boolean [...]]]></description>
			<content:encoded><![CDATA[<p>I recently put together a powershell script that can be used to update a profile property of all of the users stored in the SharePoint SSP.  At NewsGator we use a boolean property field to indicate if a particular part of our product has been activated or not.  There are some cases where this boolean flag needs to be reset for all users.   To do this I put together a simple powershell script to reset this value for all users.</p>
<p>This could easily be adapted for other users so I thought I would post share it.</p>
<pre>
<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;">$propName</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;">newsgator-x-onboarded</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$propValue</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;">true</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: #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;"> </span><span style="color: #5f9ea0; font-weight: bold;">new-object</span><span style="color: #000000;"> </span><span style="color: #800000;">Microsoft.Office.Server.UserProfiles.UserProfileManager</span><span style="color: #000000;">(</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 the SSP entries and update the property</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: #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;">;
    </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: #5f9ea0; font-weight: bold;">Write-Output</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">($count):  Setting '$propName' to '$propValue' for $u</span><span style="color: #800000;">"</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$oUser</span><span style="color: #000000;">[</span><span style="color: #800080;">$propName</span><span style="color: #000000;">].Value </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$propValue</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$oUser</span><span style="color: #000000;">.Commit();
} 

</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://vallery.net/2010/04/01/using-powershell-to-set-ssp-profile-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

