<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>chjain</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/chjain/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/chjain/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:20:54 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SharePoint 2019 Preview available for public download</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2019-preview-available-for-public-download</link>
      <pubDate>Tue, 24 Jul 2018 14:05:24 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/?p=495</guid>
      <description><![CDATA[Microsoft released a public preview of SharePoint 2019 today on the 24th Junly 2018.

The preview...]]></description>
      <content:encoded><![CDATA[Microsoft released a public preview of SharePoint 2019 today on the 24th Junly 2018.

The preview can be downloaded from Microsoft Download Center at <a href="https://www.microsoft.com/en-us/download/details.aspx?id=57169">https://www.microsoft.com/en-us/download/details.aspx?id=57169</a>

SharePoint 2019 brings a load of new features and modern capabilities to On premise SharePoint version.

<a href="https://techcommunity.microsoft.com/t5/Microsoft-SharePoint-Blog/Welcome-to-SharePoint-Server-2019-a-modern-platform-for-choice/ba-p/194162">https://techcommunity.microsoft.com/t5/Microsoft-SharePoint-Blog/Welcome-to-SharePoint-Server-2019-a-modern-platform-for-choice/ba-p/194162</a>
<h1 id="toc-hId--1540606081">Key Features</h1>
<ul>
 	<li>Modern Sites, Pages, Lists, and Libraries</li>
 	<li>Team News</li>
 	<li>SharePoint Home</li>
 	<li>Communication Sites</li>
 	<li>OneDrive Sync Client</li>
 	<li>Improved hybrid support and scenarios</li>
 	<li>New developer options</li>
 	<li>Improved support for business process with PowerApps and Flow</li>
</ul>
&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2016: PSConfigUI.exe or PSConfig.exe wouldn't start after CU install</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2016-psconfigui-exe-or-psconfig-exe-wouldnt-start-after-cu-install</link>
      <pubDate>Mon, 19 Mar 2018 23:45:05 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/?p=475</guid>
      <description><![CDATA[Howdy SharePoint admins !

I am writing this blog because it wasted about an hour of my time...]]></description>
      <content:encoded><![CDATA[Howdy SharePoint admins !

I am writing this blog because it wasted about an hour of my time trying to find a fix for it. Installed  SharePoint 2016 - Mar 2018 CU and then I tried to run the PSConfigUI.exe.

It does not come up. I click again and now it throws me the error "<span>Only one copy of the SharePoint Products Configuration Wizard can be run at a time."</span>

Hmm.. Tried to look at the event logs.. nothing there. Looked at ULS, nothing there..

Tried to restart the SP Timer Service and the service would not even stop. I was left scratching SQL instance.

Hope it helps someone out there.

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2016: How to Provision Project Web App</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2016-how-to-provision-project-web-app</link>
      <pubDate>Thu, 24 Sep 2015 15:35:44 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2015/09/24/sharepoint-2016-how-to-provision-project-web-app/</guid>
      <description><![CDATA[&#160;  Well its been almost a month when SharePoint 2016 preview was released. The content of the...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Well its been almost a month when SharePoint 2016 preview was released. The content of the blog may or may <font color="#ff0000"><u>NOT</u></font> be relevant when RTM is released.</p>  <p>I installed it on a HyperV VM with all in one servers. </p>  <p>Project Server has been a separate installer prior to this version. As a surprise and welcome move, the Project Server comes as an integral part of SharePoint 2016 Preview. No need for a separate installer.</p>  <p>Steps to provision a Project Server Web App Instance.</p>  <p>1. Create the Service Application “Project Server Service Application” by either running the Farm Config Wizard (my favorite for a Development Server) or by navigating to the Manage Service Application Page.</p>  <p>2. Start the “Project Server Service Application” service under the “Services on Server” Page.</p>  <p>3. Now, if you goto the Project Service Application, you will find that the link to create or provision a new Project Web Instance is missing. And so is the PowerShell command for New-SPProjectWebInstance. So million dollar question, how to create PW Instance? </p>  <p>4. Well, Create a New Site Collection (I chose a Team Site template, others may work too). </p>  <p>5. Once the Site Collection is created, Navigate to Site Settings –&gt; Site Collection Features.</p>  <p>6. Enable “Project Web App Settings” feature and you have the site converted to a Project Web Instance.</p>  <p>7. Now, if you navigate to the Project Server Service Application, you’ll find your site listed there.</p>  <p>8. There are couple of other Project Server related Site and Site Collection feature worth activating and trying out.</p>  <p>9. Lastly, you can change the Project Web Instance permission mode by using the PowerShell cmdlet <a href="https://technet.microsoft.com/en-us/library/jj219486.aspx">Set-SPProjectPermissionMode</a>.</p>  <p>&#160;</p>  <p>Thanks for reading. Leave comments if you have any questions.</p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013: Get all Access app instances with DB Name</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2013-get-all-access-app-instances-with-db-name</link>
      <pubDate>Thu, 17 Sep 2015 12:14:00 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2015/09/17/sharepoint-2013-get-all-access-app-instances-with-db-name/</guid>
      <description><![CDATA[&#160;  SharePoint 2013 Access Services are not new to anyone. However, once we enable the Access...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>SharePoint 2013 Access Services are not new to anyone. However, once we enable the Access Services, there is no way to govern the Service.</p>  <p>At the least, I wanted to see a report of all the Access app instances in a Web Application and what database is associated with the app.</p>  <p>I tried to find a script over the internet, but couldn’t find none ( May be it was there buried deep down). So thought of writing my own and sharing it on my blog.</p>  <p>&#160;</p>  <p>The Script goes as :</p>  <p>&#160;</p>  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> Add-PSSnapin Microsoft.SharePoint.PowerShell -ea SilentlyContinue<span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #008000"></span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #008000">$AccessAppPrincipal = &quot;75dc9906-f841-484a-b392-1ed899b92e4b&quot;;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> $AccessAppPrincipalWildCard = <span style="color: #006080">&quot;*&quot;</span> + $AccessAppPrincipal</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span> $webApplication = <span style="color: #006080">&quot;https://&lt;WEB APPLICATION URL&gt;&quot;</span><span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> <span style="color: #008000"></span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #008000">Start-SPAssignment -Global;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span> $instance = New-Object System.Collections.ArrayList<span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #008000"></span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span> <span style="color: #008000"></span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> <span style="color: #008000">Get-SPSite -WebApplication $webApplication -Limit All | Get-SPWeb -Limit All | ForEach-Object {$apps = Get-SPAppInstance -Web $_.Url | Where-Object {$_.AppPrincipalId -like $AccessAppPrincipalWildCard}| ForEach-Object {$instance.Add($_);} }</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span> Stop-SPAssignment -<span style="color: #0000ff">Global</span><span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span> <span style="color: #008000">Start-SPAssignment -Global;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span> foreach($app <span style="color: #0000ff">in</span> $instance)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span>     $web = Get-SPWeb $app.AppWebFullUrl.ToString()<span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span> <span style="color: #008000">    $app;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span>     <span style="color: #006080">&quot;DB Name: &quot;</span> + $web.AppDatabaseName<span style="color: #008000">;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span> <span style="color: #008000">    $web.Dispose();</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span> }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060">  24:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060">  25:</span> Stop-SPAssignment -<span style="color: #0000ff">Global</span><span style="color: #008000">;</span></pre>
<!--CRLF--></div>
</div>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 Hybrid Search: Create result Source &amp; Query Rule - Automation</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2013-hybrid-search-create-result-source-query-rule-automation</link>
      <pubDate>Wed, 10 Dec 2014 14:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2014/12/10/sharepoint-2013-hybrid-search-create-result-source-query-rule-automation/</guid>
      <description><![CDATA[&#160;  I know the topic starts with Hybrid Search for SharePoint 2013. But this blog is not about...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>I know the topic starts with Hybrid Search for SharePoint 2013. But this blog is not about configuring end-to-end Hybrid Search.</p>  <p>The Parent blog is <a href="https://blogs.msdn.com/b/spses/archive/2013/10/22/office-365-configure-hybrid-search-with-directory-synchronization.aspx">https://blogs.msdn.com/b/spses/archive/2013/10/22/office-365-configure-hybrid-search-with-directory-synchronization.aspx</a></p>  <p>&#160;</p>  <p>I was in process of automating the whole Hybrid process (most of the steps atleast from SharePoint using PowerShell).</p>  <p>The blog by Manas has most of the steps with scripts. However there are some manual steps involved too.</p>  <p>Thos steps are:</p>  <p>1. Creating a Result Source</p>  <p>2. Creating the Query Rule.</p>  <p>I wrote some scripts to create the result Source &amp; the Query Rule.</p>  <p><strong>Script to create the Result Source:</strong></p>  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:8d550001-647a-4dd0-96fd-9214363d2811" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 722px; height: 680px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: scroll;"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008000;">#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Input Arguments</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #000000;">
</span><span style="color: #0000FF;">param</span><span style="color: #000000;">([Parameter(Mandatory</span><span style="color: #000000;">=</span><span style="color: #0000FF;">$true</span><span style="color: #000000;">)] [string]</span><span style="color: #800080;">$RemoteSharePointUrl</span><span style="color: #000000;">, [Parameter(Mandatory</span><span style="color: #000000;">=</span><span style="color: #0000FF;">$true</span><span style="color: #000000;">)] [string]</span><span style="color: #800080;">$ResultSourceName</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;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> References and Snapins</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</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: #008080;">-not</span><span style="color: #000000;"> (Get</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin Microsoft.SharePoint.PowerShell </span><span style="color: #000000;">-</span><span style="color: #000000;">ErrorAction SilentlyContinue))
{
    Add</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin Microsoft.SharePoint.PowerShell </span><span style="color: #000000;">-</span><span style="color: #000000;">ea SilentlyContinue;
}

</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;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Variable and Constants</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #800080;">$startTime</span><span style="color: #000000;">=$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date);
</span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$debug</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$RemoteSharePointUrl</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">https://myspo.sharepoint.com</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$ResultSourceName</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">SharePoint Online</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
    
}

</span><span style="color: #800080;">$ProviderID</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">1e0c8601-2e5d-4ccb-9561-53743b5dbde7</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$logDir</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$myinvocation</span><span style="color: #000000;">.mycommand.path.Replace(</span><span style="color: #800080;">$MyInvocation</span><span style="color: #000000;">.MyCommand.name,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">) </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">\logs\</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$logFile</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$logDir</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date </span><span style="color: #000000;">-</span><span style="color: #000000;">format </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">dd_MM_yyyy_HH_mm_ss</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">) </span><span style="color: #000000;">+</span><span style="color: #000000;"> '.log';

</span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">(test</span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$logDir</span><span style="color: #000000;">)) 
{
    </span><span style="color: #800080;">$dir</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType directory </span><span style="color: #000000;">-</span><span style="color: #000000;">Path </span><span style="color: #800080;">$logDir</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$file</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType file </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

}
</span><span style="color: #0000FF;">else</span><span style="color: #000000;">
{
    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">(test</span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">)) 
    {        
        </span><span style="color: #800080;">$file</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType file </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    }
}
</span><span style="color: #008000;">#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Primary Statement Blocks</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #000000;">
try
{
    </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the Search Service Appliaction </span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$SSA</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchServiceApplication ;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Search Service Applicaion Object initialized </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the Search Service Appliaction Owner</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchOwner </span><span style="color: #000000;">-</span><span style="color: #000000;">Level SSA ;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Search Service Applicaion Owner initialized </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

    </span><span style="color: #800080;">$hash</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">@</span><span style="color: #000000;">{            
            Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$ResultSourceName</span><span style="color: #000000;">;                
            Protocol </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Remote SharePoint</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;            
            Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">SharePoint Search Results</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            RemoteSiteURL </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$RemoteSharePointUrl</span><span style="color: #000000;">;
            ProviderID </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$ProviderID</span><span style="color: #000000;">;
            QueryTemplate </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">{searchTerms}</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            Credentials </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Default</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            SearchServiceApplication </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$SSA</span><span style="color: #000000;">.Name;
        }                           

    </span><span style="color: #800080;">$resultObj</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object PSObject </span><span style="color: #000000;">-</span><span style="color: #000000;">Property </span><span style="color: #800080;">$hash</span><span style="color: #000000;"> ;

    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Trying to find if the result source exists.......</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    </span><span style="color: #008000;">#</span><span style="color: #008000;">Try getting the result source</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchResultSource </span><span style="color: #000000;">-</span><span style="color: #000000;">Owner </span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">SearchApplication </span><span style="color: #800080;">$SSA</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">Identity </span><span style="color: #800080;">$ResultSourceName</span><span style="color: #000000;">;

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Resul source does not exists, create one</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: #008080;">-not</span><span style="color: #000000;"> </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;">)
    {
        
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor White </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source not found.... Creating Result Source .....</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor White </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Creating Result Source with values </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source not found.... Creating Result Source .....</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Creating Result Source with values </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        
        </span><span style="color: #800080;">$resultObj</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$resultObj</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        try
        {
            </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchResultSource </span><span style="color: #000000;">-</span><span style="color: #000000;">Name </span><span style="color: #800080;">$ResultSourceName</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">Owner </span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">ProviderId </span><span style="color: #800080;">$ProviderID</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">SearchApplication </span><span style="color: #800080;">$SSA</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">RemoteUrl </span><span style="color: #800080;">$RemoteSharePointUrl</span><span style="color: #000000;">;    
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Green </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Success !! </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Green </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Created result Source $ResultSourceName</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

            </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Success !! Created result Source $ResultSourceName</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">

            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source Properties </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> ;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Complete ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

            </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

        }
        catch
        {
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Red </span><span style="color: #800080;">$_</span><span style="color: #000000;">;
            </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error : $_ </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        
        }
    }
    </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
    {
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Yellow </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Duplicate Result Source exists !! No action taken....</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">  ;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Duplicate Result Source exists !! No action taken....</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source Properties </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> ;

        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    }
    

}
catch
{
    Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Red </span><span style="color: #800080;">$_</span><span style="color: #000000;">;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error : $_ </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
}

</span><span style="color: #800080;">$endTime</span><span style="color: #000000;">=$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date);
Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Yellow </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Processed the script in $(($endTime-$startTime).TotalSeconds) seconds .......</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Ending Transcript...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;


</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p><strong></strong></p>

<p><strong>Script to create the Query Rule:</strong></p>

<p>&#160;</p>

<p><strong></strong></p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:3878be33-864d-4dc9-97bb-5ee119f5cfc2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 722px; height: 680px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: scroll;"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #008000;">#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Input Arguments</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #000000;">
</span><span style="color: #0000FF;">param</span><span style="color: #000000;">([Parameter(Mandatory</span><span style="color: #000000;">=</span><span style="color: #0000FF;">$true</span><span style="color: #000000;">)] [string]</span><span style="color: #800080;">$queryRuleName</span><span style="color: #000000;">, [Parameter(Mandatory</span><span style="color: #000000;">=</span><span style="color: #0000FF;">$true</span><span style="color: #000000;">)] [string]</span><span style="color: #800080;">$resultSourceName</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;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> References and Snapins</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</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: #008080;">-not</span><span style="color: #000000;"> (Get</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin Microsoft.SharePoint.PowerShell </span><span style="color: #000000;">-</span><span style="color: #000000;">ErrorAction SilentlyContinue))
{
    Add</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin Microsoft.SharePoint.PowerShell </span><span style="color: #000000;">-</span><span style="color: #000000;">ea SilentlyContinue;
}

</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;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Variable and Constants</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #800080;">$startTime</span><span style="color: #000000;">=$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date);
</span><span style="color: #800080;">$debug</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">$false</span><span style="color: #000000;">;
</span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$debug</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$queryRuleName</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">SharePoint Online QR - 2</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$resultSourceName</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">SharePoint Online</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
}

</span><span style="color: #800080;">$logDir</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$myinvocation</span><span style="color: #000000;">.mycommand.path.Replace(</span><span style="color: #800080;">$MyInvocation</span><span style="color: #000000;">.MyCommand.name,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">) </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">\logs\</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$logFile</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$logDir</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date </span><span style="color: #000000;">-</span><span style="color: #000000;">format </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">dd_MM_yyyy_HH_mm_ss</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">) </span><span style="color: #000000;">+</span><span style="color: #000000;"> '.log';

</span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">(test</span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$logDir</span><span style="color: #000000;">)) 
{
    </span><span style="color: #800080;">$dir</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType directory </span><span style="color: #000000;">-</span><span style="color: #000000;">Path </span><span style="color: #800080;">$logDir</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$file</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType file </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

}
</span><span style="color: #0000FF;">else</span><span style="color: #000000;">
{
    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">(test</span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">)) 
    {        
        </span><span style="color: #800080;">$file</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">ItemType file </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    }
}


</span><span style="color: #008000;">#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
#</span><span style="color: #008000;"> Primary Statement Blocks</span><span style="color: #008000;">
#</span><span style="color: #008000;">**************************************************************************************</span><span style="color: #008000;">
</span><span style="color: #000000;">
try
{

    Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor White </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Srcipt execution started ... </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the Search Service Appliaction </span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$SSA</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchServiceApplication ;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Search Service Applicaion Object initialized </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

    </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the Search Service Appliaction Owner</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchOwner </span><span style="color: #000000;">-</span><span style="color: #000000;">Level SSA ;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Search Service Applicaion Owner initialized </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

    </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">SPEnterpriseSearchResultSource </span><span style="color: #000000;">-</span><span style="color: #000000;">Owner </span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">SearchApplication </span><span style="color: #800080;">$SSA</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">Identity </span><span style="color: #800080;">$resultSourceName</span><span style="color: #000000;">;

    </span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$resultSource</span><span style="color: #000000;">)
    {
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host ;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor White </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source Object with name $resultSourceName found.. Continuing to create the rule for the source ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host ;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source Object found.. Continuing to create the rule for the source ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

        </span><span style="color: #800080;">$hash</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">@</span><span style="color: #000000;">{            
                    Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$resultSourceName</span><span style="color: #000000;">;
                    SearchServiceApplication </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$SSA</span><span style="color: #000000;">.Name;
                 }                           

        </span><span style="color: #800080;">$resultObj</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object PSObject </span><span style="color: #000000;">-</span><span style="color: #000000;">Property </span><span style="color: #800080;">$hash</span><span style="color: #000000;"> ;

        </span><span style="color: #008000;">#</span><span style="color: #008000;">Get the Query Rule Manager</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #800080;">$QueryRuleManager</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager(</span><span style="color: #800080;">$SSA</span><span style="color: #000000;">);
         </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Query Rule Manger object created ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;


        </span><span style="color: #008000;">#</span><span style="color: #008000;"> Create a search object filter using a $SearchOwner object  (Site collection level - in this case)</span><span style="color: #008000;">
</span><span style="color: #000000;">        </span><span style="color: #800080;">$SearchObjectFilter</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;">  New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter(</span><span style="color: #800080;">$SSAOwner</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$QueryRules</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$QueryRuleManager</span><span style="color: #000000;">.GetQueryRules(</span><span style="color: #800080;">$SearchObjectFilter</span><span style="color: #000000;">);
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Searching the query rules to find a duplicate....</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

        </span><span style="color: #800080;">$queryRule</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$QueryRules</span><span style="color: #000000;"> </span><span style="color: #000000;">|</span><span style="color: #000000;"> Where</span><span style="color: #000000;">-</span><span style="color: #000000;">Object{</span><span style="color: #800080;">$_</span><span style="color: #000000;">.DisplayName </span><span style="color: #008080;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$queryRuleName</span><span style="color: #000000;"> };
        
        
        </span><span style="color: #008000;">#</span><span style="color: #008000;"> Create a new rule as a active one if does not exists</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: #008080;">-not</span><span style="color: #000000;"> </span><span style="color: #800080;">$queryRule</span><span style="color: #000000;">)
        {
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor White </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Creating New Query Rule with Name  $queryRuleName</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
             </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Creating New Query Rule .... </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
            
            </span><span style="color: #800080;">$queryRule</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$QueryRules</span><span style="color: #000000;">.CreateQueryRule(</span><span style="color: #800080;">$queryRuleName</span><span style="color: #000000;">,</span><span style="color: #800080;">$null</span><span style="color: #000000;">,</span><span style="color: #800080;">$null</span><span style="color: #000000;">,</span><span style="color: #0000FF;">$true</span><span style="color: #000000;">);
            
            </span><span style="color: #008000;">#</span><span style="color: #008000;">Add the Result Source..</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$QuerySourceContextCondition</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;">.CreateSourceContextCondition(</span><span style="color: #800080;">$resultSource</span><span style="color: #000000;">);

            </span><span style="color: #008000;">#</span><span style="color: #008000;"> Create result block for the Query Rule</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;">.CreateQueryAction([Microsoft.Office.Server.Search.Query.Rules.QueryActionType]</span><span style="color: #000000;">::</span><span style="color: #000000;">CreateResultBlock);

            </span><span style="color: #008000;">#</span><span style="color: #008000;">Set the values as seen when creating through UI.</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.QueryTransform.OverrideProperties </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties;
            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.QueryTransform.SourceId </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$resultSource</span><span style="color: #000000;">.Id;
            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.QueryTransform.QueryTemplate </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">{subjectTerms}</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.ResultTitle.DefaultLanguageString </span><span style="color: #000000;">=</span><span style="color: #000000;"> 'Results </span><span style="color: #0000FF;">for</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">{subjectTerms}</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">';
            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.GroupTemplateId </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$QueryRuleAction</span><span style="color: #000000;">.AlwaysShow </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">$true</span><span style="color: #000000;">;

            </span><span style="color: #008000;">#</span><span style="color: #008000;">Update the object</span><span style="color: #008000;">
</span><span style="color: #000000;">            </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;">.Update();

            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Green </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Success !! New Query Rule Created ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host ;
           
            </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Success: New Query Rule created.. </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">  </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
            </span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;

            
        }
        </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
        {
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Yellow </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Dupliacte Query Rule found.. No action taken ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host ;
            </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">No Action: Dupliacte Query Rule found.. No action taken ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;">  </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        }

        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Query Rule Properties </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

        </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;"> </span><span style="color: #000000;">|</span><span style="color: #000000;"> fl;
            
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor DarkCyan </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Complete ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
            
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Step ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$QueryRule</span><span style="color: #000000;">  </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">************ Verification Complete ***********</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    }
    </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
    {
        Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Yellow </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Result Source with the name - $resultSourceName not found .. Query Rule not created ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
        </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">No Action: Result Source with the name - $resultSourceName not found .. Query Rule not created ...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">  </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
    }
    
}
catch
{
    Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Red </span><span style="color: #800080;">$_</span><span style="color: #000000;">;
    </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error: $_ </span><span style="color: #800000;">&quot;</span><span style="color: #000000;">  </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
}

</span><span style="color: #800080;">$endTime</span><span style="color: #000000;">=$</span><span style="color: #000000;">(Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date);
Write</span><span style="color: #000000;">-</span><span style="color: #000000;">Host </span><span style="color: #000000;">-</span><span style="color: #000000;">ForegroundColor Yellow </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Processed the script in $(($endTime-$startTime).TotalSeconds) seconds .......</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Ending Transcript...</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">$logFile</span><span style="color: #000000;">;
</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>&#160;</p>

<p>N.B. – Query Rules can be very complicated and can have different combinations. The above script creates the Query Rule as mentioned in the <a href="https://blogs.msdn.com/b/spses/archive/2013/10/22/office-365-configure-hybrid-search-with-directory-synchronization.aspx" target="_blank">blog</a> by Manas for Hybrid Search.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/57/99/01/HybridSearch%20-Automation.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-57-99-01/HybridSearch-_2D00_Automation.zip">HybridSearch -Automation.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>PowerShell ISE: Make ISE ready for SharePoint cmdlets</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/powershell-ise-make-ise-ready-for-sharepoint-cmdlets</link>
      <pubDate>Tue, 02 Dec 2014 18:08:40 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2014/12/02/powershell-ise-make-ise-ready-for-sharepoint-cmdlets/</guid>
      <description><![CDATA[&#160;  As SharePoint administrators and developers we do use Windows PowerShell cmdlets for...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>As SharePoint administrators and developers we do use Windows PowerShell cmdlets for creating SharePoint scripts.</p>  <p>PowerShell ISE is very powerful tool for scripting. However, we need to load the SharePoint snap-in everytime we load ISE to work with SharePoint cmdlets.</p>  <p>I know it’s not a big deal for most people, but for folks like me who do not want to type it everytime I open PowerShell ISE window, I would rather prefer it to be loaded automatically as it does for SharePoint Management Shell.</p>  <p>I know there are numerous blogs out there for the same requirement. Most of (all) the blogs I found involve doing some manual step by copying and pasting stuff in some file. I wouldn’t do that. Run a script and it should do it for me.</p>  <p>So, I am writing this blog.</p>  <p>This simple script would do the trick and you run it once and forget it.</p>  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:74866aa9-2d2e-4c67-912e-aaf33d88ad15" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 722px; height: 209px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">(test</span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$profile</span><span style="color: #000000;">.AllUsersAllHosts)) 
{
    new</span><span style="color: #000000;">-</span><span style="color: #000000;">item </span><span style="color: #000000;">-</span><span style="color: #000000;">type file </span><span style="color: #000000;">-</span><span style="color: #000000;">path </span><span style="color: #800080;">$profile</span><span style="color: #000000;">.AllUsersAllHosts </span><span style="color: #000000;">-</span><span style="color: #000000;">force;
}
</span><span style="color: #008000;">#</span><span style="color: #008000;">Clear-Content $profile.AllUsersAllHosts;</span><span style="color: #008000;">
</span><span style="color: #000000;">Add</span><span style="color: #000000;">-</span><span style="color: #000000;">Content </span><span style="color: #800080;">$profile</span><span style="color: #000000;">.AllUsersAllHosts '</span><span style="color: #800080;">$ver</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$host</span><span style="color: #000000;"> </span><span style="color: #000000;">|</span><span style="color: #000000;"> select version;
</span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$ver</span><span style="color: #000000;">.Version.Major </span><span style="color: #008080;">-gt</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">) 
{
    </span><span style="color: #800080;">$host</span><span style="color: #000000;">.Runspace.ThreadOptions </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">ReuseThread</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
}
</span><span style="color: #0000FF;">if</span><span style="color: #000000;"> ((Get</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.SharePoint.PowerShell</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">ErrorAction SilentlyContinue) </span><span style="color: #008080;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$null</span><span style="color: #000000;">) {
    Add</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.SharePoint.PowerShell</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
}';</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p><strong>A little (mind it !) explanation:</strong></p>

<p>The script would open the profile file for <strong>All Users</strong> (so it would be for all users using PowerShell ISE on that machine) &amp; <strong>All Hosts</strong> (PowerShell ISE or PowerShell command Prompt). If the profile file is not created, it would create one. Once created, it’ll push the content in that file.</p>

<p><strong>N.B.</strong> It will append the text to the existing file. So if you run multiple times, you’ll have the same coded added multiple times. Wouldn’t make much difference except ISE would have to go through the code unnecessarily.</p>

<p>You can verify the contents using :</p>

<div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:64d2d72f-8535-4ad2-93f4-306f55efa995" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 391px; height: 27px;background-color:White;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #000000;">psEdit </span><span style="color: #800080;">$profile</span><span style="color: #000000;">.AllUsersAllHosts;</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>

<p>When ISE loads it loads the profile file automatically and it loads the SharePoint snap-in for you.</p>

<p>That’s it.. You can now focus on your development more by a minute than loading the snap-in every time.</p>

<p><strong>And yeah</strong>, if you want to do it for your account only, use $profile.CurrentUserAllHosts instead of $profile.AllUsersAllHosts in the script.</p>]]></content:encoded>
    </item>
    <item>
      <title>Fix: Document Sets Shared Column not inheriting metadata</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/fix-document-sets-shared-column-not-inheriting-metadata</link>
      <pubDate>Mon, 06 Oct 2014 16:03:12 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2014/10/06/fix-document-sets-shared-column-not-inheriting-metadata/</guid>
      <description><![CDATA[&#160;  I am writing this blog to address the issue with the Document Set items not inheriting the...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>I am writing this blog to address the issue with the Document Set items not inheriting the metadata value defined for the Document Set.</p>  <p><strong><u>Problem:</u></strong></p>  <p>You have created a Document Set in a library, you have set the metadata for the Document Set and you add new files to the Document Set. You expect that the metadata set for Document Set needs to be inherited by the Child Items, but is not happening.</p>  <p>First thing, you need to check if you have configured Shared Columns properly for the Document Set. </p>  <p><strong>Not sure, how to configure Document Set or How to propagate the metadata automatically to the items in the Document Set? </strong></p>  <p>Well, for that check out the link - <a title="https://office.microsoft.com/en-001/sharepoint-server-help/create-and-configure-a-new-document-set-content-type-HA101782461.aspx" href="https://office.microsoft.com/en-001/sharepoint-server-help/create-and-configure-a-new-document-set-content-type-HA101782461.aspx" target="_blank">Create and configure a new Document Set content type</a></p>  <p>Once you have verified that you have done the steps correctly as mentioned in the above article, we can move to the next step.</p>  <p><strong><u>Cause:</u></strong></p>  <p>There could be numerous cause why it may not work. The most common being missing or corrupted Document Set Event Receivers. </p>  <p>In this blog we are going to address how to fix the missing or corrupt Event&#160; Receivers for the library that are responsible for setting the metadata for the Child Items in the Document Set.</p>  <p>In total, there are 6 event receivers that are added to a library when you add the Document Set Content Type to the library.</p>  <p>I have created the script that will add or replace corrupted Event Receivers. </p>  <p>Set the values for the WebURL &amp; Library name in the script below and run the script using Farm account on any of the servers and hopefully your Document Sets should have the metadata propagated.</p>  <p></p>  <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:b82dce58-b697-4db3-9e51-ea6d4827a8fb" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 722px; height: 674px;background-color:White;overflow: scroll;"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
https://www.CodeHighlighter.com/

--><span style="color: #000000;">Add</span><span style="color: #000000;">-</span><span style="color: #000000;">PSSnapin Microsoft.SharePoint.PowerShell </span><span style="color: #000000;">-</span><span style="color: #000000;">ea SilentlyContinue;
</span><span style="color: #800080;">$webURL</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">&lt;Enter Web URL&gt;</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$libraryName</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">&lt;Enter Library Name&gt;</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

</span><span style="color: #008000;">#</span><span style="color: #008000;">Set to true if you want to see some debug info</span><span style="color: #008000;">
</span><span style="color: #800080;">$debugInfo</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">$false</span><span style="color: #000000;">;



</span><span style="color: #008000;">#</span><span style="color: #008000;">###########################################################</span><span style="color: #008000;">
#</span><span style="color: #008000;">               Do not change below code                   #</span><span style="color: #008000;">
#</span><span style="color: #008000;">###########################################################</span><span style="color: #008000;">
</span><span style="color: #000000;">



</span><span style="color: #800080;">$web</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Spweb </span><span style="color: #800080;">$webURL</span><span style="color: #000000;">;
</span><span style="color: #800080;">$docsLib</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$web</span><span style="color: #000000;">.Lists[</span><span style="color: #800080;">$libraryName</span><span style="color: #000000;">];

</span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$debugInfo</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.Title;
    </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Count;
    </span><span style="color: #800080;">$evtrcvrs1</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers </span><span style="color: #000000;">|</span><span style="color: #000000;"> where{</span><span style="color: #800080;">$_</span><span style="color: #000000;">.Class </span><span style="color: #008080;">-eq</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #008080;">-or</span><span style="color: #000000;"> </span><span style="color: #800080;">$_</span><span style="color: #000000;">.Class </span><span style="color: #008080;">-eq</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> };
    </span><span style="color: #800080;">$evtrcvrs1</span><span style="color: #000000;">.Count;
}

</span><span style="color: #800080;">$assembly</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$class</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$class2</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;

</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemAdding;
</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocumentSet ItemAdding</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr1</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemAdding;
</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocSetItemsEventReceiver ItemAdding</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr2</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemUpdating;
</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocumentSet ItemUpdating</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr3</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemUpdating;
</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocSetItemsEventReceiver ItemUpdating</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr4</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemAdded;
</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocumentSet ItemAdded</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr5</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.EventReceivers.Add();

</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Assembly </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$assembly</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Class </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$class2</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Type </span><span style="color: #000000;">=</span><span style="color: #000000;"> [Microsoft.SharePoint.SPEventReceiverType]</span><span style="color: #000000;">::</span><span style="color: #000000;">ItemUpdated;
</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DocumentSet ItemUpdated</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Synchronization </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Synchronous</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rcvr6</span><span style="color: #000000;">.Update();

</span><span style="color: #800080;">$docsLib</span><span style="color: #000000;">.Update();
</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  https://dunnhq.com --></div>]]></content:encoded>
    </item>
    <item>
      <title>How to: Use ListData.svc as a External Content Type through BCS</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/how-to-use-listdata-svc-as-a-external-content-type-through-bcs</link>
      <pubDate>Tue, 14 Jan 2014 12:53:38 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2014/01/14/how-to-use-listdata-svc-as-a-external-content-type-through-bcs/</guid>
      <description><![CDATA[I came up with this nice scenario where a user wanted to import the ListData.svc from SharePoint...]]></description>
      <content:encoded><![CDATA[<p></p>  <p>I came up with this nice scenario where a user wanted to import the ListData.svc from SharePoint as an External Content Type in SharePoint.</p>  <p>The requirement was to use a List as an External List in a different site collection.</p>  <p>The first thought that will cross the mind is that you can use SharePoint Designer to import a WCF Service. But ListData.svc cannot be imported in SharePoint Designer.</p>  <p>There are numerous ways to import a ListData.svc and one of the ways mostly talked about is to consume the service in a .NET assembly and import the .NET assembly as a External Content Type. That would work too.</p>  <p>But I was keen in finding a more easier way where I can create a model file and import it in the BCS Service Application through Central Admin site.</p>  <p>Well for that you have to create the model file first. Manually creating the .bdcm file? Tedious !! I would say.</p>  <p>Well I used Visual Studio 2012 to do it for me. Yes!! Visual Studio 2012!!</p>  <p></p>  <p>Follow the steps below to create the .bdcm file.</p>  <p>1. Open Visual Studio 2012 &amp; Create a new SharePoint App Project.</p>  <p>2. Provide the necessary details for Name and the deployment site.</p>  <p>3. Select the type as SharePoint hosted</p>  <p>4. Once the project is created, “Add Content Types for an External DataSource ..” by right clicking on the project and navigating to the Add Menu and choose the last option.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/3515.image_1AD88810.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/3515.image_5F00_1AD88810.png" target="_blank"><img title="image" style="margin: 0px; display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/3542.image_thumb_639200D4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/3542.image_5F00_thumb_5F00_639200D4.png" width="553" height="112" /></a> </p>  <p>5.&#160; This will bring up a screen where you can provide the URL for the OData Service and provide a name.</p>  <p>6. Enter the ListData.svc URL you want to use in the OData Service URL box and provide a desired name for the Data Source.</p>  <p>7. SharePoint will try connecting to the Service and List the entities available.</p>  <p>8. Select the Entity (List) you want to use, and click Finish.</p>  <p>9. Visual Studio will create the External Content Type and the list instance for you (if you had selected the check box)</p>  <p>10. Now Select the Content Type by navigating to the folder created in Visual Studio. The file extension is .ect.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/5040.image_79E7A619.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/5040.image_5F00_79E7A619.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/8231.image_thumb_02D73859.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/8231.image_5F00_thumb_5F00_02D73859.png" width="272" height="185" /></a> </p>  <p>11. View the Properties of the file in the Properties Window.</p>  <p>12. We are going to set the credentials that the BCS Service Application is going to use to call the service. We are going to use a Secure Store Target Application to store the credentials and use it. Lets Assume we created the Secure Store Target Application with the name “ListAccessAccount”. Now in the Properties window for the .ect file in Visual Studio, we are going to set the credentials for Windows Authentication Access using the windows credentials stored in “ListAccessAccount”.</p>  <p>13. Set the value for both the properties -&#160; “<strong>ODataServiceAuthenticationMode</strong>” and the “<strong>ODataServiceMetadataAuthenticationMode</strong>” as WindowsCredentials.</p>  <p>14. Set the value for the property “<strong>SsoProviderImplementation</strong>” as “<strong>Microsoft.Office.SecureStoreService.Server.SecureStoreProvider, Microsoft.Office.SecureStoreService, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</strong>”</p>  <p>15. Build and Publish the APP. Don’t worry we are not going to import the App.</p>  <p>16. Now navigate to the project’s folder and use windows search to search for “*.bdcm” file in the folder.</p>  <p>17. You will find only 1 file with the name BDCMetadata.bdcm</p>  <p>18. Open the file in a text editor (notepad.exe).</p>  <p>19. Now do a find for “<strong>SsoProviderImplementation</strong>” in the notepad.</p>  <p>20. You will find 2 places where the property is defined. We are going to add our own property just above the found property. The value of the Property should be as below: (Note the value I am using ListAccessAccount. You need to change the value to the name of the Secure Store Target Appliaction you created)</p>  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Property</span> <span class="attr">Name</span><span class="kwrd">=&quot;SsoApplicationId&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;System.String&quot;</span><span class="kwrd">&gt;</span>ListAccessAccount<span class="kwrd">&lt;/</span><span class="html">Property</span><span class="kwrd">&gt;</span></pre>


<p>21. After adding the property it should look like below. Make sure you have added the property twice where you found the “<strong>SsoProviderImplementation</strong>” property.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/1222.image_71F29468.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/1222.image_5F00_71F29468.png"><img title="image" style="display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/21/metablogapi/3324.image_thumb_0195302B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-21-metablogapi/3324.image_5F00_thumb_5F00_0195302B.png" width="855" height="39" /></a></p>

<p>22. Now we are done with the .bdcm file. </p>

<p>23. Next navigate to the BCS Service Application in your Central Admin site and import the model file.</p>

<p>24. Done !!</p>

<p>25. Once the import has happened you should see your BDC model, External System and External Content Type.</p>

<p>26. You can create list based on your External Content Type through the SharePoint UI by creating an External list.</p>

<p></p>

<p>Voila!! </p>

<p>Note – We are using Windows credentials in the Secure Store Target Application as we started on the assumption that the SharePoint Web Application from which we are going to consume data is using Windows Authentication. </p>

<p>Hope this helps some one out there !! Its going to be there for my reference for sure..</p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint Online: Pass Credentials to Web Service passively</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-online-pass-credentials-to-web-service-passively</link>
      <pubDate>Thu, 28 Nov 2013 10:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2013/11/28/sharepoint-online-pass-credentials-to-web-service-passively/</guid>
      <description><![CDATA[&nbsp;
SharePoint Online or Office 365 relies on Claims authentication. This makes things a little...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>SharePoint Online or Office 365 relies on Claims authentication. This makes things a little challenging when you are trying to work with the Web Services exposed by SPO. When I was trying to consume web Services with Default Credentials passed, it started throwing me Access Denied (401).</p>
<p>After little research I was able to come up with numerous code samples which would make use of the ClaimClientContext.GetAuthenticatedCookies method.</p>
<p>This method works fine as long as you are using the Application in User Interactive mode. The reason being it uses the Web Browser in a Form and asks for credentials. It then retrieves the cookie from the browser which can be passed along with the Web Service Headers.</p>
<p>The sample for such code is here: <a href="https://blogs.msdn.com/b/sharepointdev/archive/2011/05/12/connecting-to-sharepoint-online-web-services.aspx" target="_blank">Connecting to SharePoint Online Web Services</a></p>
<p><span style="font-size: medium;"><span style="text-decoration: underline;">Now the Big Question</span></span></p>
<p>How do I pass the credentials in a Passive mode ? How to pass credentials from a non user interactive application ?</p>
<p>Well, it took a while for me to figure out that and finally got the answer. The answer is with the SharePointOnlineCredentials Class.</p>
<p>You can use the <a href="https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.sharepointonlinecredentials.getauthenticationcookie.aspx" target="_blank">GetAuthenticationCookie</a> method to get the Cookie. I will show how you can pass your credentials from the code later in this blog.</p>
<p>The return type for this cookie is not a FedAuth cookie and hence it cannot be directly passed along with the Web Service Request.</p>
<p>Hence we will rip the contents of the cookie and create a new FedAuth Cookie which we can pass along with the web service to authenticate against a SPO site.</p>
<p>The whole code to get the cookie and create a FedAuth cookie is below</p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main(<span style="color: #0000ff;">string</span>[] args)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">        {            </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #0000ff;">string</span> targetSiteURL = <span style="color: #006080;">@"https://&lt;SPO Site URL&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            var targetSite = <span style="color: #0000ff;">new</span> Uri(targetSiteURL);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            var login = <span style="color: #006080;">"&lt;SPO User Name&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            var password = <span style="color: #006080;">"&lt;SPO User Password&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            var securePassword = <span style="color: #0000ff;">new</span> SecureString();</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            <span style="color: #0000ff;">foreach</span> (<span style="color: #0000ff;">char</span> c <span style="color: #0000ff;">in</span> password)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                securePassword.AppendChar(c);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            SharePointOnlineCredentials onlineCredentials = <span style="color: #0000ff;">new</span> SharePointOnlineCredentials(login, securePassword);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            CallSPOServiceWithoutPopup(targetSite, onlineCredentials);            </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">        }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> CallSPOServiceWithoutPopup(Uri targetSite, SharePointOnlineCredentials onlineCredentials)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">        {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            <span style="color: #008000;">//I had added the reference of the Lists Service - You can add any</span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            Lists list = <span style="color: #0000ff;">new</span> Lists();</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            list.UseDefaultCredentials = <span style="color: #0000ff;">false</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            <span style="color: #0000ff;">string</span> authCookieValue = onlineCredentials.GetAuthenticationCookie(targetSite);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            list.CookieContainer = <span style="color: #0000ff;">new</span> CookieContainer();</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            list.CookieContainer.Add(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                <span style="color: #0000ff;">new</span> Cookie(<span style="color: #006080;">"FedAuth"</span>,</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                authCookieValue.TrimStart(<span style="color: #006080;">"SPOIDCRL="</span>.ToCharArray()),<span style="color: #008000;">//This is to remove the prefix from the cookie's value</span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                String.Empty,</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                targetSite.Authority));</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            list.Url = <span style="color: #006080;">@"&lt;Web Service URL&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            <span style="color: #0000ff;">string</span> listName = <span style="color: #006080;">"Shared Documents"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #0000ff;">string</span> rowLimit = <span style="color: #006080;">"5"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #008000;">// Instantiate an XmlDocument object </span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            System.Xml.XmlDocument xmlDoc = <span style="color: #0000ff;">new</span> System.Xml.XmlDocument();</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            System.Xml.XmlElement query = xmlDoc.CreateElement(<span style="color: #006080;">"Query"</span>);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            System.Xml.XmlElement viewFields = xmlDoc.CreateElement(<span style="color: #006080;">"ViewFields"</span>);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            System.Xml.XmlElement queryOptions = xmlDoc.CreateElement(<span style="color: #006080;">"QueryOptions"</span>);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">&nbsp;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #008000;">//*Use CAML query*/ </span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            query.InnerXml = <span style="color: #006080;">"&lt;Where&gt;&lt;Gt&gt;&lt;FieldRef Name=\"ID\" /&gt;"</span> + </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                <span style="color: #006080;">"&lt;Value Type=\"Counter\"&gt;0&lt;/Value&gt;&lt;/Gt&gt;&lt;/Where&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            viewFields.InnerXml = <span style="color: #006080;">"&lt;FieldRef Name=\"Title\" /&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #008000;">//queryOptions.InnerXml = "";</span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            queryOptions.InnerXml = </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                <span style="color: #006080;">"&lt;IncludeMandatoryColumns&gt;FALSE&lt;/IncludeMandatoryColumns&gt;"</span> + </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                <span style="color: #006080;">"&lt;DateInUtc&gt;TRUE&lt;/DateInUtc&gt;"</span>;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            System.Xml.XmlNode nodes = </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                list.GetListItems(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                    listName, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                    viewName, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                    query, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                    viewFields, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                    rowLimit, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                    <span style="color: #0000ff;">null</span>, </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                    <span style="color: #0000ff;">string</span>.Empty);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            <span style="color: #0000ff;">string</span> ixml = list.GetList(listName).InnerXml;</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            Console.WriteLine(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                <span style="color: #006080;">"Retrieving title of all the items in SharePoint Online"</span> +</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                 <span style="color: #006080;">"sites 'Shared Documents' using Lists webservice"</span>);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            Console.WriteLine(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                <span style="color: #006080;">"==========================================="</span> +</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                <span style="color: #006080;">"============================================="</span>);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            <span style="color: #0000ff;">foreach</span> (System.Xml.XmlNode node <span style="color: #0000ff;">in</span> nodes)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                <span style="color: #0000ff;">if</span> (node.Name == <span style="color: #006080;">"rs:data"</span>)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                    <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> i = 0; i &lt; node.ChildNodes.Count; i++)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                    {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                        <span style="color: #0000ff;">if</span> (node.ChildNodes[i].Name == <span style="color: #006080;">"z:row"</span>)</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                        {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                            Console.WriteLine(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                                node.ChildNodes[i].Attributes[<span style="color: #006080;">"ows_Title"</span>].Value);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                        }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">                    }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">                }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">            }</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">            Console.ReadLine();            </pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">        }</pre>
<!--CRLF--></div>
</div>
<p>&nbsp;</p>
<p>With the above sample you can call the SPO web Services in unattended mode (in Scheduled jobs or any application that would not run in non User Interaction mode).</p>
<p>&nbsp;</p>
<p>Hope this sample helps!!</p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2010 PowerShell or PowerShell ISE throwing - “The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.” when loading SharePoint PowerShell module</title>
      <link>https://docs.microsoft.com/archive/blogs/chjain/sharepoint-2010-powershell-or-powershell-ise-throwing-the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered-when-loading-sharepoint-powershell-module</link>
      <pubDate>Fri, 09 Aug 2013 08:24:18 GMT</pubDate>
      <dc:creator><![CDATA[Chanchal J]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chjain/2013/08/09/sharepoint-2010-powershell-or-powershell-ise-throwing-the-local-farm-is-not-accessible-cmdlets-with-featuredependencyid-are-not-registered-when-loading-sharepoint-powershell-module/</guid>
      <description><![CDATA[&#160;  Recently I started facing this issue.  Whenever, I load the PowerShell ISE and Type the...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Recently I started facing this issue.</p>  <p>Whenever, I load the PowerShell ISE and Type the command to load the SharePoint PowerShell module, it starts throwing error </p>  <p>“The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.”</p>  <p>The same error comes up in the SharePoint Management Shell.</p>  <p>The reason could be you installed Windows Management Framework 3.0 via Windows Update or manually.</p>  <p>If you like Windows to automatically update in the background or you do it manually, but don’t read through each KB, the same could happen in your SP 2010 farm.</p>  <p>The KB that causes this is <a href="https://www.microsoft.com/en-us/download/details.aspx?id=34595">https://www.microsoft.com/en-us/download/details.aspx?id=34595</a>.</p>  <p>It installs Windows Management Framework 3.0 and then PowerShell will start loading .Net framework 4.0.</p>  <p>SharePoint 2010 does not like .Net 4.0 and starts failing.</p>  <p>Resolution: <a href="https://support.microsoft.com/kb/2796733">https://support.microsoft.com/kb/2796733</a></p>  <p><b>OR</b></p>  <p>(What I have done)</p>  <p>Go to Control Panel –&gt; Program &amp; Features –&gt; View Installed Updates and Search for the KB that corresponds to your Server’s patch version &amp; uninstall that KB. Post uninstallation reboot the server.</p>  <p>· Windows Server 2008 R2 SP1</p>  <p>· 64-bit versions: Windows6.1-KB2506143-x64.msu</p>  <p>· Windows Server 2008 Service Pack 2</p>  <p>· 64-bit versions: Windows6.0-KB2506146-x64.msu</p>  <p>· 32-bit versions: Windows6.0-KB2506146-x86.msu</p>  <p>N.B. The above info is valid for SharePoint 2010 only.</p>]]></content:encoded>
    </item>
  </channel>
</rss>