RSS
Twitter
LinkedIn

 

Search Active Directory Objects with PowerShell, SQL, BCS and SharePoint Search - Part 3

SharePoint provides import and search capabilities for User Accounts and Security Groups stored in Active Directory (AD) via the use of FIM, the User Profile Service, My-Sites and the SharePoint Search Service.

The following article(s) detail how other Objects stored in Active Directory (AD) can be made available in SharePoint Search Results via the use of PowerShell, SQL, BCS and SharePoint Search Display Templates.

 

Part 3:

Finally, we're going to create a Content Source (pointing at the BCS External Data Source created in Step 2) and a Custom Result Page using SharePoint Search.

 

Using the PowerShell below, a Content Source can be created by executing the following command:

.\CreateBCSSearchContentSource.ps1 -SearchApplicationName "Search Service Application" -contentSourceName "AD2SPDataADComputersViaBCS" -LOBSystemName "SQLSvrName-AD2SPData-Read" -LOBInstanceName "SQLSvrName-AD2SPData-Read"

 

(CreateBCSSearchContentSource.ps1)

 


 

In addition to creating the Content Source the ‘CreateBCSSearchContentSource.ps1‘ script also runs a "Full Crawl".
Assuming the "Full Crawl" completes successfully (which confirms Step 1 and Step 2 were configured correctly), SharePoint automatically creates the relevant "Crawled Properties" within the SharePoint Search Schema.

 

 

However, before we can create the Custom Search Results Page we also need to create the relevant "Managed Properties" and "Map them to the relevant Crawled Property".

 

Again, using the PowerShell below (along with the ‘ManagedSearchProperties.csv' file provided), this can be achieved by executing the following command:

.\CreateManagedSearchProps.ps1 -ManagedPropertiesCSVFileName "ManagedSearchProperties.csv"


(CreateManagedSearchProps.ps1)

 

 

After the "Managed Properties" have been created successfully run another "Full Crawl" of the Content Source (this ensures the new "Managed Properties" are added to/included in the SharePoint Search results)

 

Now we can move on to setting up the Search Results page.

Open your "Enterprise Search Centre" site (or create one if you haven't already), navigate to the "Pages" document library and created a new Search Results Page (for this example I have create a page called "ADComputers.aspx"


 

Then navigate to your "Search Settings" page (via "Site Settings > Search Settings")...
 

... and ‘Add a Link' to the newly created ‘AD Computers' Search Results page.

 

Next we're going to upload (and publish) the ‘Custom Search Display Templates' that we're going to use on the ‘AD Computers' Search Results page.

To do this, open the "Root Site" and navigate to:

http://<youspwebapplicationurl>/_catalogs/masterpage/Forms/Display Templates.aspx?RootFolder=/_catalogs/masterpage/Display Templates/Search

 

From the Ribbon click "Files > Upload Document" and upload the "Item_ADComputer.html" and "Item_ADComputer_HoverPanel.html" files provided and "Publish a Major Version" for each.

(this process should automatically create "Item_ADComputer.js" and "Item_ADComputer_HoverPanel.js" files)


Next return to the "ADComputers.aspx" Custom Search Results page we created previously and select "Edit Page"...

 

... and edit the "Search Results Web Part" to display the "Web Part Properties".

 

Click "Change Query" and set the "Query text" field to:

{searchboxquery}* ContentSource:<yourSearchContentSourceName>

 

 

... and click "OK"

 

Then expand the "Display Templates" section, click "Use a single template to display items" and finally select "AD Computer Item" from the drop down.

 

Click to "Apply" and/or "OK" to save these changes to "Search Results Web Part Properties".

Save and Publish the updated "ADComputers.aspx" Custom Search Results page.

 

When a search is then performed via the "ADComputers.aspx" Custom Search Results page a list of matching Search Results are displayed with the relevant the object metadata information retrieved from Active Directory.


 

 

Happy Coding…

 

 

Please download attached zip for "full/complete .ps1" files - Examples provided above are simplified abbreviation

download  SearchADPowerShellSQLSharePoint.zip

 

 

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add