Update Application Pool Password using PowerShell Script

By using below script we can update Passwod of Specific User for all his assigned Application Pool

PowerShell Script:


Import-Module WebAdministration
$applicationPools = Get-ChildItem IIS:\AppPools | where { $_.processModel.userName -eq "SPServer\administrator" }
 
foreach($pool in $applicationPools)
{
    $pool.processModel.userName = "SPServer\administrator"
    $pool.processModel.password = "sp#123@admin"
    $pool.processModel.identityType = 3
    $pool | Set-Item
}
 
Write-Host "Password Sucessfully Updated." -ForegroundColor Magenta 
Write-Host "" 

log4net With SharePoint 2016

Log4net library is a tool to help the programmer output log statements to a variety of output targets.

You may use below steps to configure Log4Net in SharePoint 2016 On Premise.

For this demonstration I have used my SharePoint Site: http://sps2012:1111/Pages/default.aspx

First Create SharePoint Solution

Next select Deploy as Farm Solution as we need to Deploy Log4Net DLL on our SharePoint Server GAC.

Here I am going to create 2 separate projects. 1 For Logging Application and 2 for SharePoint Web Parts where we can create our web parts. We can modify Logging Project as per our requirement without making any kind of changes in Web Parts Project.

Next let’s install Log4Net using NuGet Package Manager

Select Project -> Right Click on Project – >Select Manage NuGet Packages

Search Or Browse for log4net by Apache Software Foundation

Click on Install

When you click on Install it will preview changes which is going to be added in project

Click on Ok and it will install log4Net in Project

After Installation we are able to see Log4Net reference in project

Next Step is to build solution

Once we build solution we are able to see log4net.dll in Debug folder of solution.

Now we need to use this DLL: log4net.dll in SharePoint Web Part Project. So that we can create web part and check Logging Functionality.

Create WebPart in SP.WebParts Projects.

I have added WebPart and also updated its information as shown in Image

Now we need to refer Log4Net.dll in project

Navigate to Project -> References -> Right Click on Add Reference

It will open window. Click on Browse and select log4Net.dll file. Make sure you select correct file which we have added in SP.Log4Net.Solution Project. You can also copy log4Net.dll from bin folder and keep it on your desired location where you can assign reference to project.

Once you click on Ok it will add reference in Web Parts Project.

For Demonstration purpose I am going to add button on Visual Web Part and on its click event going to add Log Information so that we can create log using log4Net.dll file.

I have added button into web part and added Log Information. Now we are able to deploy this solution on SharePoint.

Also we need to keep in mind that Log4Net.Dll is also needs to deploy with Visual Web Part so that SharePoint Server can refer it in application.

To add custom dll reference in SharePoint Select Package and Open it.

Navigate to Advance

Click on Add Existing Assembly (As we already have log4Net.dll)

And select log4Net.dll from your project or saved directory location

Click on OK and this will add log4Net.dll in project’s package which eventually deploys dll in GAC.

Save Project and deploy it

Till now we have added log4Net.dll into project and its reference for logging mechanism. But we also needs to configure require information for Log4Net.

We can configure Log4Net configuration in SharePoint Web Application Web.Config and global.asax File.

As you are aware that we are using our SharePoint Application: : http://sps2012:1111/Pages/default.aspx

Next Navigate to C:\inetpub\wwwroot\wss\VirtualDirectories\1111 where we are able to find global.asax and web.config file.

Add Following code in global.asax


<%@ Assembly Name="Microsoft.SharePoint"%><%@ Application Language="C#" Inherits="Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication" %>
<%@ Assembly Name="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" %>
<%@ Import Namespace="log4net" %>
<%@ Import Namespace="log4net.Config" %>
<%@ Import Namespace="System.IO" %>

<script language="C#" runat="server">
void Application_Start(object sender, EventArgs e)
    {      
		log4net.Config.XmlConfigurator.Configure(new FileInfo("C:\\inetpub\\wwwroot\\wss\\VirtualDirectories\\1111\\web.config"));     
    }
</script>


Note: If you are getting an error while adding log4net dll information in Global.asax then it may be due to dll is not added in GAC.
You may read my post regarding How to Add DLL in GAC and How to Get DLL Publickeytoken

Now let’s updateWeb.Config File

Open Web.config file

And add below section in “<configSections>”


<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />

Also Add below configuration in “<configuration>” section


<log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\LOGS\log4net\Logs\ApplicationLog" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <datePattern value=".yyyyMMdd-HHmm" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ERROR" />
      <appender-ref ref="RollingFileAppender" />
      <appender-ref ref="SmtpAppender" />
    </root>
  </log4net>

Note that you can change or update this log4Net configuration as per your own requirement.I have added Configuration value so that I can create log on each minute with dynamic file name added HHMM value.

Now we are done with all configurations and it’s time to test functionality.I have created Page named “CustomLog.aspx” and added web part Custom Log on it.

Now when we click button Add Log Information it will create log with string “Log Detail Information” on our mentioned location. Make sure here location is file Creation location which we have mentioned in web.config file for log4net configuration.

Once you click button you can see log as below

Also note that I have configured log mechanism as per each minute so that we can create or see log on each and every minute as shown in below image

From above steps we learn how we can configure log4Net with SharePoint 2016.

SharePoint Framework SPFX On SharePoint Server 2016

To use SharePoint Framework SPFX on SharePoint Server 2016 we need to install SharePoint 2016 Feature Pack 2.

SharePoint 2016 Feature Pack 2 supports SharePoint Framework client-side web parts hosted in classic SharePoint pages.

SharePoint 2016 Feature Pack 2 supports SharePoint Framework client-side web parts hosted on classic SharePoint pages built by using the SharePoint Framework v1.1.0. This means that when you are targeting the SharePoint 2016 platform, you need to use the SharePoint Framework v1.1.0 due to the server-side version dependencies.

Install following prerequisite to develop SharePoint Framework SPFX.

  • Nodejs (Download Link: https://nodejs.org/en/) Make sure you install node version 6.11.2
  • Gulp Version 3.9.1
  • Yeoman Template Generator 2.0.2
  • NPM Version 3.10.10
  • SharePoint Framework Yeoman Generator Version 1.0.2
  • Visual Studio Code or any other editor (Visual Studio Code: https://code.visualstudio.com)

Please make sure that you install Microsoft Template Generator Version 1.0.2 any other version will not work for SharePoint 2016 On Premise.

My Environment:

Installation of Yeoman Template Generator

Installed Package Version

Package Installation Command


npm install -g yo gulp


	npm install npm@3.10.10


npm install -g @microsoft/generator-sharepoint@1.0.2

Create New SPFX Solution using command


yo @microsoft/sharepoint

Give Solution Name, Web Part Name and other required information as shown in Image

Once Solution is created it will appear as shown below

Now let’s make changes in created solution. You can open it using command


code .

Once you enter command it will open in Visual Studio Code Editor.

We are going to update HTML Code in file: HelloSpfxWebPart.ts

You can reach HelloSpfxWebPart.ts file from solution location SPFX\src\webparts\helloSpfx\HelloSpfxWebPart.ts

I have added my name”Nilesh Rathod” in html text/tag.

You can make changes as per your requirement.

Now next task is to test SPFX Solution/WebPart on SharePoint Server environment.

Before that we are going to run command “gulp trust-dev-cert” so that when we run our SPFX webpart on local machine it will not give Certificate Error


gulp trust-dev-cert

After that you can add command “gulp serve” to run this SPFX Solution/WebPart on local environment.

When you run gulp serve command it will open browser with URL: https://localhost:4321/temp/workbench.html which contains modern UI for SharePoint Web Part.

Here you can insert web part as shown in image

Once you add Web Part on Page, it will appear as per our updated changes.

Now we are able to Create and Run Web Part on SharePoint Server 2016 environment.

Next step is to deploy it on SharePoint Server Environment.

Deployment of SPFX WebPart on SharePoint Server 2016

Now when we are going to deploy WebPart on SharePoint Server we also needs to keep on mind that we need to add its related js file or configuration file which is required to run that SPFX application.

When we build our WebPart it will create its configuration file which are required on server to run it without any dependency.

While working with SharePoint Framework WebPart we can assign that location name from where it can read files when we are going to deploy it on any server.

That configuration is called CDN Path which is available in Configuration -> write-manifests.json file.

I have created Document Library named MySPFXFiles on my site location http://sps2012:4444/MySPFXFiles where I can add all required files which will be my CDN Address for SPFX Web Part.

You can set your own document library on your application and can use it as CDN Address.

We can set CDN Path as shown in image

After adding CDN Path let’s ship solution by running command



gulp bundle --ship


This builds the minified assets required to upload to the CDN provider. The –ship indicates the build tool to build for distribution. You should also notice that the output of the build tools indicate the Build Target is SHIP.

Next run command


gulp package-solution --ship

This creates the updated client-side solution package in the sharepoint\solution folder.

Once we run above command it will prepare 2 locations which we needs to consideration for actual deployment on server.

  • One location is “SPFX\sharepoint\solution” where our actual app package file “spfx-soln.sppkg” is generated.
  • Another location is “SPFX\temp\deploy” where all other mandatory file to run SPFX WebPart is generated.

Note that we can easily check or configure “temp\deploy” folder location in solution copy-assets.json file which is location at SPFX\config\copy-assets.json.

Now let’s copy all files on required file from temp\deploy folder to SharePoint Serve.

Open Solution in Folder. You can open it from command prompt also using command

explorer .

Navigate to Temp Deploy Folder Location: SPFX\temp\deploy

Here SharePoint 2016 will not allow to copy JSON file to SharePoint as it is blocked by environment. To enable it please check my post for Allow JSON to SharePoint 2016.

Copy all files and upload into SharePoint CDN Location which we already mentioned in above steps.

In my case it is : http://sps2012:4444/MySPFXFiles

I have copied all files on CDN address as shown in above Image.

Once all required file is copied next step is to deploy app on SharePoint App Catalog

If you are not aware How to Configure SharePoint App Catalog or How to setup App Domain on SharePoint Server you may refer to my post.

SharePoint Server 2016 Configure APP Domain

and

SharePoint Server App Catalog Configuration

Navigate to SPFX\sharepoint\solution location

Now Upload App File spfx-soln.sppkg on SharePoint App Catalog

When you upload package it will ask us to deploy application. You can click on Deploy button and trust application. You may also check your given CDN address is also available on application.

Once you click Deploy, SPFX Solution will deploy on SharePoint Server 2016 you can also check is Deployed Column value as shown in below Image

Once Application is deployed in App Catalog Site it will available in your desired site under Your Application -> Application From your Organization

Click on that app and it will install on server. You can see Installed application as shown in below image

Now you can add SPFX WebPart on any page.

I have created page named SPFXAPP.aspx Edit Page and Click on Insert Web Part Link . You may find SPFX WebPart in “Under Development” section.

Add HelloSPFX WebPart on Page and it will appear as shown in below Image.

Check In and Publish Page.

Hence we learn How to Create SPFX Solution on SharePoint Server 2016 Environment and Deployment Of SharePoint Framework WebPart or Solution on SharePoint Server 2016.

How to Setup App Domain on SharePoint Server 2016

To setup and configure APP Domain On SharePoint Server use below steps.

Open DNS Manager on Server

Find DNS and Open it

Select Forward Lookup Zone

Right Click on Forward Lookup Zone and Click on New Zone

It will start New Zone Wizard

Click on Next

Select Primary Zone

Click On Next

Select Second Option running all DNS server in this domain option

Click Next

Enter Zone Name

Click Next

Select Dynamic Update option Allow Only Secure Update

Click Next

Finish New Wizard.

Click on Finish

It will created newly assigned Forward Lookup Zone: sharepointapps.com

Right Click on sharepointapps.com and click on New Alias (CNAME)

Add New Resource Record

Here Add Alias Name “*” and set Fully Qualified Domain Name (FQDN) by browse file selection and select existing server (same as parent folder) option.

Click OK

Now Lookup Forward Zone is configured here.

Next Step is to Configure SharePoint Service: App Management Service Application

Navigate to SharePoint Central Administration

Click on Application Management -> Manage Service Applications

Create App Management Service

Click New and Select App Management Service

It will create App Management Service as shown in image

Once Application is created run below command to setup

Run the SharePoint 2016 Management Shell as an administrator

Start the SPAdminV4 and SPTimerV4 service applications


net start SPAdminV4
net start SPTimerV4

Also Set the domain used to host apps to the new zone created above


Set-SPAppDomain "sharepointapps.com"

Start the AppManagementServiceInstance and SPSubscriptionSettingsServiceInstance service instances:



Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance





Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"}


Create the SharePoint Subscription Service:

Note that I have used my server “SPS2012” here for SPManagedAccount you can use your own server.


$account = Get-SPManagedAccount "SPS2012"
$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
$appPoolAppSvc = New-SPServiceApplicationPool -Name AppServiceAppPool -Account $account
$appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPoolSubSvc –Name SettingsServiceApp –DatabaseName SettingsServiceDB
$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc
$appAppSvc = New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name AppServiceApp -DatabaseName AppServiceDB
$proxyAppSvc = New-SPAppManagementServiceApplicationProxy -ServiceApplication $appAppSvc


Set the name for the site subscription:



Set-SPAppSiteSubscriptionName -Name "app" -Confirm:$false


Here App Domain Service for SharePoint is configured successfully.

Now you can use App Service for your developer site or any other site collection.