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

     

     

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

    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 2:

    Next we’re going to create an External Content Type (ECT) using the Business Connectivity Service (BCS) available in SharePoint.

    Before we can do this, we first need to store some ‘Windows Credentials” in the SharePoint ‘Secure Store’, which will be used by the Business Connectivity Service to connect to the SQL Database previously created in ‘Part 1’.

     

    Using the PowerShell below, this can be achieved by executing the following command:

    .\CreateSecureStoreTargetApp.ps1 -SiteUrl "http://<yourspwebappurl>" -SecureStoreTargetAppName "AD2SPDataCreds" -SecureStoreTargetAppDispName "AD2SPDataCreds" -SecureStoreTargetAppEmail "<youremail@domain.com>" -SecureStoreTargetAppAdmin "<yourdomain>\SP_Admin" -SecureStoreTargetAppGroup "<yourdomain>\Domain Users" -SecureStoreTargetApp_CredUserAccount "<yourdomain>\yourSQL_Access_Account" -SecureStoreTargetApp_CredPassword "<yourSQL_Access_Account_Password>"

     
    (CreateSecureStoreTargetApp.ps1)

     

    Now we have credentials stored, we can create the External Content Type for the ‘ADComputers’ SQL table.

    External Content Types can be created using SharePoint Designer…

     

     

     

    However, for this particular example (and in true Blue Peter style) we’re going to ‘Import’ a BCS Model file (.bdcm) which I created earlier and exported from SharePoint Designer...
     

     

    To do this we’re going to first use PowerShell to ‘Update the BCS Model’ with the relevant SQL Server, SQL Database, SQL Table and Secure Store Target App information.

    Before finally Importing the ‘BCS Model’ into the Business Connectivity Service and setting the permissions accordingly

     

    Using the PowerShell below (along with the ‘ADComputer-template.bdcm’ file provided), this can be achieved by executing the following command:

    .\UpdateImport_BCSModel.ps1 -SiteUrl "http://<yourspwebappurl>" -BCSModelTemplateFileName "ADComputer-template.bdcm" -BCSModelOutputFileName "ADComputers.bdcm" -DbServerName "<yourSQLServerName>" -DbName "<yourAD2SPDatabaseName>" -TableName "ADComputers" -SecureStoreAppID "<yourAD2SPDataSecureStoreTargetAppName>" -BCSEntityAdmin "<yourDomain>\SP_Admin" -BCSEntityUsers "<yourDomain>\SP_Crawl_Account"

     


    (UpdateImport-BCSModel.ps1)

     

     

    Read Part 3 ...

     

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

    downloadSearchADPowerShellSQLSharePoint.zip

     

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

    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 1:

    To begin with we're going to create a SQL database using PowerShell.

     

    Next we’re going to create a simple SQL Table that will hold the object metadata retrieved from AD.

     

     

    Finally, we’re going to populate the SQL Table with information retrieved from AD using the ‘Get-ADComputer’ PowerShell CmdLet

    (For this example we’re getting a list of Computers and their OS details)

     

    Resulting in a populated SQL Table.
     

     

     

    Read Part 2 ...

     

     

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

    download  SearchADPowerShellSQLSharePoint.zip

     

     

  Older Posts »