In this article we will look for developing a logging mechanism for PowerShell automation components that can provide logs not just in form of a flat file but also as interactive html format. This best part of the story is we can design this html log format using whatever html/Css elements to make as intuitive as possible.

For the sake of clear understanding I am going to explain the complete process in various steps-

We need to download & install the “EnhancedHTML2” module.

In Step 1 we can see the command to download & install the module. We can use this command using PowerShell Console

Or we can download & install this module manually as shown in Step 2 from the PowerShell Gallery

In Step 3 we have added the code to query for all Lists in SharePoint Site, I keep it simple & straight for this demo

In Step 4 we have added code to build a collection keep list of SharePoint Lists using a PowerShell hash table as shown below-

In Step 5&6 we can see the implementation of “EnhancedHTML2” module

In Step 5 we will convert the data collection (Row & Column format) to “EnhancedHTMLFragment” by using “ConvertTo-EnhancedHTMLFragment” cmdlet. Similarly we can create any number of HTML Fragments as per our need

This cmdlet uses a switch “PreContent” that allows you to any HTML snippet before the fragment add to the HTML outcome

“-MakeTableDynamic” switch allows the cmdlet to embed basic html plumbing like Search, Pagination and so on to the HTML outcome

In Step 6 we will append all the HTML Fragments to build a single HTML file by using “ConvertTo-EnhancedHTML” cmdlet.

This cmdlet has got “HTMLFragments” parameter that will accept comma separated values of names of the Fragments that you want to include in the HTML document

Another important parameter “CssUri” accept the path of CSS file that will define the styling attributes for the HTML page

“Out-File” parameter defines the path to the save the HTML Log file

In Step 7 we will call the method to execute above steps

Step 8 the dlls that we need to include the script to make SharePoint Calls work

Step 9 shows the CSS file that we referred with “ConvertTo-EnhancedHTML” in Step 6

In Step 11 & 12 we can explore the html generated as part of this execution and it is amazing to see how this HTML is structured by adding references to the required JavaScript files and body elements.

It can be clearly noticed the generated html body content is in the form of table structure, this happened since we specified “-As Table” switch with “ConvertTo-EnhancedHTMLFragment” cmdlet in Step 5

Also we can notice the “<h1>” tag in the HTML body, it is the same content that we include to the fragment using “-PreContent” switch with “ConvertTo-EnhancedHTMLFragment” cmdlet in Step 5

And finally we can see the HTML based interactive logs in Step 13 shown below. This would be feature rich HTML Page and we can even further add more feature as per our needs, thought this would cost additional effort.

In this article we will discuss implementing “Alternate Access Mapping” or commonly known as “AAM” in SharePoint 2016.

If you are not aware of AAM or you have some misconceptions about it, I would highly recommend you to read through an excellent blog Alternate Access Mappings (AAMs) *Explained by “Brain Pendergrass” from Microsoft and would like to thank him for such an awesome blog to make me understand this concept in depth.

This article will focus on guided steps to configure AAM in SharePoint 2016 and we won’t discuss AAM as a concept.

Create New Web Application

Step 1: To start the demo let go to SharePoint Central Admin Site and click on “Manage Web Applications” as shown below-

I am creating a new Web Application for demo purpose. In real environments we can use any existing Web Application to perform these steps.

If operation completed successfully we can see popup window show success message

We can see this new Host added to the existing list

Add/Update IIS Bindings

Step 6: Add “IIS” Bindings

Now we have to add IIS bindings for the new Host. Search for “IIS” and select “Internet Information Services (IIS) Manager”

Select the Web Application that we have created in above steps from the “Connections” Panel on the left under “Sites” node

Click on “Bindings…” on the right to Add/Edit Web Application Bindings

In the “Site Bindings” screen select the default binding and click “Edit”

In the “Edit Site Binding” screen enter Host Name value and this should match the entry that we have created earlier in DNS

Click OK

Once saved the existing binding will look like as shown below-

Configure Alternate Access Mappings Using Central Admin

Step 7: Configure Alternate Access Mappings (From Central Admin)

Go To Central Admin -> “Application Management”

Under Web Applications Click “Configure alternate access mappings”

Click “Edit Public URLs”

In the “Edit Public Zone URLs” Screen and enter “Default Zone” URL with “Host Name” configured earlier as shown below.

Click “Save” once you entered the default Zone URL to save the data.

Now try accessing SharePoint Web Application using Public Zone URL and if the configuration goes well, the access will be granted to you

Test Alternate Access Mappings

Configure Another Mapping

Step 8: Repeat Step 5 to add another DNS entry to add a new Host Name

Step 9: Repeat Step 6 to Add Web Application Bindings

Configure Alternate Access Mappings Using PowerShell

Step 10: Configure Alternate Access Mappings (Using PowerShell)

Now we will add this new Host Name to the default zone for the web application

Launch SharePoint 2016 Management Shell

“New-SPAlternateURL” cmdlet gives us option to add new Alternate URLs to the required zone for web application

This cmdlet take following parameters

New Alternate URL – URL that you need to register as alternate URL

Web Application Path – URL that represent Web Application

Zone – Represents a zone that you need this alternate URL to add to

Once this command executes successfully we can a new Alternate Access Mapping added to the list

Test Alternate Access Mapping

Now if try to access this web application using this new mapping it still be translated to the same Public URL for the Web Application.

By following above steps we can enable a web application that receives the request from an internal URL in one of the five authenticated zones to return pages that contain links to the public URL for the zone

While working with a whole range of applications using SharePoint Platform & Services I have come across lot of issues specially while dealing with SharePoint User Information let it by user names entered by application users on the UI or by querying user information by User ID.

In most scenarios you will need this to query data for the users based on User ID from within code itself. I have add a little User Interface in this article to make sure you get the idea on how this approach will work and what all properties will be exposed as results.

Here is the process flow that depicts the flow of information between Client Request & Server Response:

To start with the demo I have add some of HTML elements to prepare the UI with a textbox to enter User ID as shown below-

In the below screen shot you can see the simple HTML markup for the user interface.

We have a textbox where users can enter user id of the SharePoint User

In order to display the results I have add a HTML table as container. Purpose is to prepare HTML on the fly and paste it at runtime into this container.

In Step 1 we have bound the blur event of the textbox to a function that will execute the query against the User Data based on the User ID

In Step 2 we call another helper function “getUserById” by passing user id to it. This function call return a jQuery promise which can be further evaluated in upcoming steps

In Step 3 we will check if the JQuery call has been completed or not by using JQuery “when” construct.

In Step 4 we will call another helper function “renderUser” once the JQuery call has been completed in Step 3. The “renderUser” function is responsible to render User Information into the container.

In Step 5 we call “_api/Web” REST API endpoint can using its function “getUserById”, during this call we will specify “json” as datatype to ensure that we will get results in “json” format

In Step 6 we are rendering the details of the user in the container

And here is the final output of the operation performed.

So we can see Title, Login Name, Email returned back for a specific User Id as shown below-

Usage & Health Service Application is one of the most important Service Applications that provides vital information on the Health & State of SharePoint Farm.

In SharePoint 2016, Usage Service is collecting information on Timer Service Monitoring, Event Logs, Performance Counters, Search Usage, Sandbox Usage, and Site Collection Usage and much more.

This Service application is responsible to keep monitoring the resource, health & state associated with the SharePoint Farm and logs this information to Log Files on SharePoint Hive or any designated path along with SharePoint Logging Database “WSS_Logging” in SQL Server Database.

Many other components in SharePoint like Developer Dashboard, Search Analytics, Web Analytics Reports are using this data to provide logical User Interface for the end users.

You will get empty reports in Web Analytics reports section, if usage and health data collection service application is not configured properly.

It is not possible to Provision Usage & Health Service using Central Admin, as there is no User Interface available.

Let us first get into Central Admin Site to see if there is options available on the User Interface to provision Usage Service

Go to “Central Admin” – > “Manage Service Applications”

Click on “New” Menu on the Ribbon and in the existing list of available Service Application Templates we can see there is no template available for provisioning “Usage & Health Service Application”

This concludes that we have to provision Usage Service using PowerShell as shown in the following steps-

Launch “SharePoint 2016 Management Shell”

Step 1: Provision Service Application Instance

In this step, we will provision the Usage Service using “New- SPUsageApplication” cmdlet as shown below

New-SPUsageApplication -Name "Usage and Health Data Collection"

Step 2: Provision Service Application Proxy

In this step, we will provision Service Application Proxy for Usage Service by using the following commands

There are many SharePoint Components like InfoPath Form Services, Visio, Search Service, Workflows and many more, relies on SharePoint State Service Application to application sessions across related HTTP(S) requests in a SQL Server Database.

In this article, we will discuss the steps involved in configuring SharePoint State Service Application using PowerShell

First, let us go to Central Administration Site to make sure that State Service Application is not available to be provisioned from the UI.

Go to “Central Administration” -> “Application Management” and click on “Manage Service Application”

On Service Application Page, Click “New” Menu in Ribbon Bar to see list of Service Applications that we provision from this UI and we can see State Service Application is missing from this list

That means we can provision this Service Application only using PowerShell and that what we are going to do in this article.

In order to provision the service application using PowerShell, launch “SharePoint 2016 Management Shell” and perform the following steps-

Step 1: Provision Service Application Instance

In this step we will provision the State Service using “New-SPStateServiceApplication” cmdlet as shown below

New-SPStateServiceApplication -Name "State Service Application"

Step 2: Provision Service Application Proxy

In this step we will provision Service Application Proxy for State Service by using the following command

In this article we will discuss how to provision Search Service Application for SharePoint 2016 using PowerShell

During this whole article I will guide you steps involved in provisioning Search Application along with the corresponding PowerShell Script

Here the steps that we will explore in the upcoming section-

Though we can provision Search Application from Central Admin as well but the purpose here is to demonstrate the use of PowerShell commands required to provision Search Application so that’s what we will do.

First let’s go to Central Admin to ensure that there is no existing instance of Search Service Application has been provisioned earlier

Under Application Management -> Click on “Manage Service Applications”

Here we can see what all Service Application Instances provisioned earlier and we can see there are none

Now launch SharePoint Management Shell to run the required PowerShell commands

We will run the PowerShell commands in the following order to make sure each Sub component provisioned as desired.

Step 1: Provision Service Application Instance

In this Step we will first provision Search Service Application using the following cmdlet-

Step 3: Validate Service Instance

Next step is to validate that the Service Instance is online and to do so we can use the following cmdlet

Get-SPEnterpriseSearchServiceInstance -local

Step 4: Clone Topology

Next step is to clone the topology which is required in order to make any changes to the search topology in a search installation that has items in the search index

As per Microsoft recommendation around this you need to modify this new topology object, which is a clone of the active topology, by adding or removing search components. After you have made the changes to the clone topology object, you have to activate this clone to have this topology in action.

$clone = $sa.ActiveTopology.Clone()

Step 5: Get Search Service Instance Server Name

This Server name is required in the upcoming steps to it is wise to make use of the following cmdlet to retrieve the server name

Get-SPEnterpriseSearchServiceInstance| Select Server

Step 6: Get Search Service Instance

Then we get handle over the search service instance running on the respective server using the following cmdlet

Step 7: Provision Admin Component

Next step is to provision a new Admin Component for the given topology and search service instance using the following cmdlet. This cmdlet is using reference to search service instance we get in the earlier steps

RootDirectory: Specifies the root directory that will hold the index location for the new search index component. If you plan to isolate the index on dedicated discs in order to avoid I/O contention that may leads to performance degradation as it might be a risk that index filling up the OS disk and ruin the overall server performance.

Step 12: Provision Query Component

And finally we have to provision new query processing component for the given topology and search service instance using the following cmdlet

Step 13: Activate New Topology

Once all the components has been added to the new topology, activate it by using following cmdlet

$clone.Activate()

Step 14: Clean Inactive Topologies

Finally we have to clean all the inactive topologies associated with a search service application. We can perform this clean by using the following the code using “Remove-SPEnterpriseSearchTopology” cmdlet

Request Body

Once we execute this request we can inspect the response to ensure that the request item has been added successfully to the Categories List.

Also we can validate this new item added by browsing Categories List

Update List Item

http://<Host Name>/_api/Web/Lists/getByTitle('Categories')/Items(9)

For update request you have to include “eTag” value that was returned with the item during the initial query to the Request Body. SharePoint uses this value to determine if there is any updates made to the item since it is last queried.

“If-Match: *” can be used to match any “eTag” value resulting in the operation being performed regardless of the actual value.