SHAREPOINT MIGRATION – EXPORT Alternate Access Mapping

This is article is next in the series of articles on “SharePoint Migration & Planning” Strategies. You can reach out to the previous articles in this series using the following links:

  1. SHAREPOINT MIGRATION: PLANNING & GUIDANCE ON SHAREPOINT OBJECTS
  2. SHAREPOINT MIGRATION – EXPORT IIS SETTINGS

In this article we will look for the PowerShell Scripts to export “Alternate Access Mapping (AAMs)” Settings from source SharePoint Farm. This information will be helpful to track all the “AAMs” defined in SharePoint Farm.

In Step 1 we will add the PowerShell Snapin to PowerShell Script as usual

1

In Step 2 we define a function and initiate the export CSV file with Column Headers. For this demo I am exporting a few important properties like “Incoming Url, Zone, Public Url” but you may query all possible properties as you deemed fit

In Step 3 we execute the “Get-SPAlternateURL” cmdlet to query the required properties

In Step 4 we loop through the properties collection for all AAM Mapping and list out the queried properties for each mapping

In Step 5 we add the content of properties for each of the AAM Mapping to the CSV file

2

In Step 6 we will set the settings file path and call the function to export the AAM Mappings

3

Once this script get executed successfully, it will export the AAM Mappings in a CSV File as shown below in Step 7

4

We can see the exported mappings as shown below in Step 8

5

Code Reference:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"Add-PSSnapin "Microsoft.SharePoint.PowerShell"
function Get-Alternate-Access-URLs(){ Try {        if (Test-Path $settingsFilePath)        {            Remove-Item $settingsFilePath        }
        Add-Content $settingsFilePath "Incoming Url, Zone, Public Url"
        $aamSettings = Get-SPAlternateURL | Select IncomingUrl,Zone,PublicUrl
        foreach ($aamSetting in $aamSettings)        {            $incomingUrl = $aamSetting.IncomingUrl            $zone = $aamSetting.Zone            $publicUrl = $aamSetting.PublicUrl
            $settings = "$incomingUrl, $zone, $publicUrl"             Add-content $settingsFilePath $settings        }    }    Catch {         Write-Host $Error -ForegroundColor Yellow }}
Clear-Host
$settingsFilePath = "C:\Prashant\PowerShell\SharePoint Migration\PowerShell - Get-Alternate-Access-URLs\Alternate-Access-Urls.csv"
Get-Alternate-Access-URLs

That is all for this demo.

Hope you find it helpful.

Advertisements

SharePoint Migration – Export IIS Settings

This is article is next in the series of articles on “SharePoint Migration & Planning” Strategies. You can reach out to the previous articles in this series using the following links:

SharePoint Migration: Planning & Guidance On SharePoint Objects

In this article we will look for the PowerShell Scripts to export IIS Settings from source SharePoint Farm. This information will be helpful to track all the “Application Pool” accounts used to configure Web Applications in the Farm.

There could be more properties that you can export but for this demo I am considering following important properties:

Site Name, Site Path, Application Pool, Bindings, Identity, Password

In Step 1 we will import module “WebAdministration” which gives us the methods to work with “IIS Manager” Objects

1

In Step 2 we will retrieve items from IIS directory using wildcard path search “IIS:\Sites\*”

In Step 3 we will enlist the header of the output Settings file by using the name of properties that we are pulling from IIS

In Step 4 we will fetch properties “Site Name, Site Path, Application Pool, Bindings, Identity, Password” for each IIS Site

In Step 5 we will append the properties to the output file for each of the IIS sites we have in Farm

2

In Step 6 we are specifying the path for output file which would be in the form of CSV

In Step 7 we are calling the function executing Step 1-6

3

Once the script executed successfully it will generate the output file as shown below-

4

And here is the data that was added to the output file during the execution of the above script

We can see IIS details for each Site (Web Application) added to the SharePoint Farm and this information is really crucial to document during the Migration planning phase.

5

Code Reference:

Import-Module WebAdministration
function Get-IIS-Settings(){    param($ListName,$ScriptPath,$FileDateTimeStamp) Try {        if (Test-Path $settingsFilePath)        {            Remove-Item $settingsFilePath        }
        $iisSites = Get-Item IIS:\Sites\*
        Add-Content $settingsFilePath "Site Name , Site Path , Application Pool , Bindings , Identity , Password"
        foreach ($iisSite in $iisSites)        {            $appPoolName = $iisSite.ApplicationPool            $appPool = get-item "IIS:\AppPools\$appPoolName"            $processModel = $appPool.processModel            $appPoolIdentity = $processModel.username            $appPoolIdentityPassword = $processModel.password            $iisBindings = $iisSite.Bindings            $iisBindingCollection = $iisBindings.Collection             $siteName = $iisSite.Name            $sitePath = $iisSite.physicalPath
            $settings = "$siteName, $sitePath, $appPoolName,$iisBindingCollection,$appPoolIdentity, $appPoolIdentityPassword"             Add-content $settingsFilePath $settings        }
    }    Catch {         Write-Host $Error -ForegroundColor Yellow }}
Clear-Host
$settingsFilePath = "C:\Prashant\PowerShell\SharePoint Migration\IISSettings.csv"
Get-IIS-Settings

Hope you find it helpful.

SharePoint Migration: Planning & Guidance on SharePoint Objects

1

While performing SharePoint Migration we need to do lot of planning before actually starting even with the basic step on migration.

Planning includes well defined list of SharePoint Artifacts, Settings, or Configurations that must be identified beforehand and accordingly migration strategy can be worked out.

SharePoint Migration involves the following stages:

  • Inventory Audits
  • Configuration Migration
  • Schema Migration
  • Data Migration
  • Validation

In this article I will explain you detailed list of SharePoint Inventory that must be pulled out and kept stored as backup safely atleast during the migration phase.

 SharePoint Inventory Map

Below is the small Inventory Map for SharePoint Objects & Artifacts that we should always consider during the Planning Phase for SharePoint Migration.

In the upcoming sections of this article we discuss each of the Object/Artifact in more details from data collection stand point.

2

SharePoint Objects & Properties

Here is list of objects that should be queried during the initiation phase of migration.

SharePoint Farm

We should query SharePoint Farm Object to get it Properties, Configurations settings, Level of SharePoint Logging and Server details which are associated to this farm

 

3

Configuration & Settings

We should query SharePoint to get configuration settings for IIS, SharePoint Designer, Alternate Access and Common Web Service (SPServiceHostConfig)

4

Databases

We should query SharePoint to get details on databases designated as Content & Configuration databases associated with current Farm

5

Web Application, Sites, (Site Map)

We should query SharePoint to get details on Web Applications, Site Collections, Sites Subsites (Site Map), Site Templates especially the custom templates if you want to have sites based on these custom templates at destination too

6

Lists & Libraries

We should query SharePoint to get details on List Schema, Item Count, List Permissions, Item Specific Permissions if any and also report of large lists. This information will very helpful while migrating Schema & data at later stage of Migration process

7

Accounts, Authentication & Claim Providers

We should query SharePoint to get details on Managed Accounts, Application Pool Accounts, Authentication Providers and Installed Certificates Information.

8

Custom Solutions

We should query SharePoint to get details on custom WebParts, Features, Time Jobs, Layout Pages and other solutions (WSPs). This information is really important to migrate or rewrite functionalities as deemed fit. We also need to gather source code for each of the custom solutions as it might be required during migration issues encountered during/after migration.

9

Service Applications

We should query SharePoint to get details on Service Applications, Application Instances, Load Balancer Configuration. Information on Server Applications is important to help understand and troubleshoot issues during/after migration

10

Business Connectivity Service Applications

We should query SharePoint to get details on configuration settings for BCS data connection files. This will be really important to know all connection details for LOBs connected using BCS.

11

Search Service Applications

Search is one of the most complex Service applications when it comes to migration. So it really important that we should detailed out each granular piece of information associated with Search service applications.

We should query SharePoint to get details on configuration settings for Search Service Applications, Query Keywords, Query Scope, Query Rules, Query Suggestion, Ranking Model, Security Trimmer, and Application Proxies.

12

Application Specific Properties & Settings for Service Applications

Most Service applications expose a set of properties specific to each of them. It is important detailed out all possible details on each of application specific properties that we can query from SharePoint as shown below

13

I will keep on updating this article as I get more relevant information to include so that it could be proved as one stop reference for SharePoint Migration Guidance.

In the upcoming articles on SharePoint Migration I will show you implementation details on how to gather the inventory for each of the above mention objects.

So stay tuned.

Hope you find it helpful.

SharePoint Online: Working With List Content Types Using PowerShell

In this article we will discuss the configuration of some of the important operations on Content Type for SharePoint Online Lists. Though I have taken only a handful of operations to showcase in this demo, but remember there are lot more to explore.

Operation: How to enable “Content Types” for List

We can see this setting available under “Advanced Settings” for the list as shown below-

1

We can play with this setting using PowerShell as described below-

2

In Step 1 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 2 we will set “ContentTypesEnabled” to True

In Step 3 we will update the list property by calling “Update” method

In Step 4 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 5 we will display success message to the Users if Step 4 executes successfully

In Step 6 we will call function that we have explained in Step 1-5

3

Once this script executes successfully we can see list setting updated by navigating “Advanced Settings” of the list as shown below-

4

Operation: How to “Add Existing Content Type To List”

We can see this setting available under “List Settings” for the list as shown below-

5

We can play with this setting using PowerShell as described below-

6

In Step 1 we will get the object reference to the respective Web

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get the object reference to the respective list by calling “GetById” method on Content Types collection

In Step 4 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 5 we will display success message to the Users if Step 4 executes successfully

In Step 6 we will call function that we have explained in Step 1-5

7

Once this script executes successfully we can see a new content type added by navigating “List Settings” of the list as shown below-

We can notice the new content type added to the List Content Types Collection

8

Operation: How to “Get List of All Content Types”

We can see this setting available under “List Settings” for the list as shown below-

9

We can play with this setting using PowerShell as described below-

10

In Step 1 we will get the object reference to the respective Web in context of which this code is executing

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get List Content Types Collection

In Step 4 we call the “Load” function to retrieve List Content Types Collection properties from server

In Step 5 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 6 & 7 we will loop through the Content Types Collection and display relevant properties (ex. Name, ID and so on) from the collection

In Step 8 we will call function that we have explained in Step 1-7

11

Once this script executes successfully we can see list of content types by navigating “List Settings” of the list as shown below-

12

Operation: How to “Delete Existing Content Types” From List

We can see the List of Content Types already added to List under “List Settings” as shown below-

12

We can delete any Content Type from list by using PowerShell by using PowerShell as described below-

13

In Step 1 we will get the object reference to the respective Web in context of which this code is executing

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get List Content Types Collection

In Step 4 we call the “Load” function to retrieve List Content Types Collection properties from server

In Step 5 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 6 we will loop through the Content Types Collection

In Step 7 we will look for required content types that are intended to delete. In this example we will compare the Content Type Name to ensure that only intended content type are deleted

In Step 8 we will call “DeleteObject” method to delete the respective content type from Content Types Collection of List

In Step 9 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 10 we will display success message after Step 9 got executed successfully

In Step 11 we will call function that we have explained in Step 1-10

14

Once this script is executed successfully the respective content type will be deleted from Content Types List and this can we verified from the UI by navigating through “List Settings”

15

That is all for this demo.

Hope you find it helpful.

SharePoint Online: Working With List Fields Using PowerShell

In this article we will discuss the operations on List Fields (Columns), which involves Getting All Columns, Adding New Columns, Updating Existing Columns and so on.

To start with this demo we will start with a list called “Products” and perform all operations on this list.

1

Operation: How to Add New Columns To List

We can add a new column to the list by making use of the following code.

2

In Step 1 we will get the object reference to the current Web using Client Context properties

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will define the xml of the List Column schema. You can get this XML by prototyping the list using SharePoint UI and then by using SharePoint Client Browser to look for Schema XML for Lists & Fields.

In Step 4 we will call “AddFieldAsXml” method to add field as xml schema to the list

In Step 5 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 6 we will display the success message to the users

In Step 7 we will call function that we have explained in Step 1-5

We can see this field added to the list by browsing the list

4

We can see the details of the new column (Datatype and others) by browsing List Settings

5

Operation: How Get All Columns of List

We can get all columns used in a list by making use of the following code.

6

In Step 1 we will get the object reference to the current Web using Client Context properties

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get the object reference to Fields collection of the list

In Step 4 we call the “Load” function to retrieve Fields collection properties from server

In Step 5 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 6 we will loop through the collection and display Field details to the users

In Step 7 we will call function that we have explained in Step 1-6

We can see the fields collection to the list by browsing the list

7

Operation: How to Update column of List

Let’s consider that we have to add little description the field Title, which is blank currently

8

We can update an existing column to the list by making use of the following code.

9

In Step 1 we will get the object reference to the current Web using Client Context properties

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get the object reference to the respective field by calling “GetByTitle” method

In Step 4 we will set the Description property of List object with the required value

In Step 5 we will call “Update” method to save these changes back to SharePoint List

In Step 6 we will call “Load” method to retrieve updated properties (Description) of the field from Server

In Step 7 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 8 we will display Field details to the users to the users

In Step 7 we will call function that we have explained in Step 1-8

10

We can see description of Title field is update to the list by browsing the field properties under list settings

11

Operation: How To Add Existing Site Columns To List

Since we are planning to add an existing Site Column to the list, it is necessary to ensure the existence of Site Column. We can verify this by navigating “Site Settings > Site Columns”.

For this demo I already have added a Site Column “ProductOwner” that we can see under “Custom Columns” group as shown below-

12

And we can also verify the list settings to ensure that “ProductOwner” Column is not added to the list earlier

13

Now we will look into code to add existing Site Column to the list as explained below-

14

In Step 1 we will get the object reference to the current Web using Client Context properties

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get the object reference to Fields collection of the Web. It is important to note that Site Columns are the part of Web Fields Collection not List Fields Collection. So we have to make use of Web object reference to look for existing Site Columns.

In Step 4 we call the “Add” function on “Fields” Collection of the list to add the reference of the Site Column from Step 3

In Step 5 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 6 we will call function that we have explained in Step 1-5

We can see the field collection to the list by browsing the list settings-

16

We can further look into column details by clicking it

17

Operation: How Set Default Value For Field

We can set default values to SharePoint List Fields programmatically by using the following code as explained below-

18

In Step 1 we will get the object reference to the current Web using Client Context properties

In Step 2 we will get the object reference to the respective list by calling “GetByTitle” method

In Step 3 we will get the object reference to Fields collection of the list

In Step 4 we will call “DefaultValue” property of Field Object and assign it a value of our choice

In Step 5 we will call “Update” method of Field Object, which will update the “DefaultValue” property back into database

In Step 6 we will send the batch request to SharePoint Server for processing by calling “ExecuteQuery” method

In Step 7 we will display the a success message which is informing users about the status of operation

In Step 8 we will call function that we have explained in Step 1-7

19

We can see this value shown as default value whenever a new Item has been created (programmatically or using browser) as shown below-

20

That is all for this demo.

Hope you find it helpful.

SharePoint Online: Working with Lists Using PowerShell

In this article we will discuss SharePoint List operations using PowerShell for SharePoint Online.

To start with this demo, I have created a demo SharePoint Online Site that I will use to perform SharePoint operations in this and few of the upcoming articles in this series.

1

In case you are not aware of on how to start with PowerShell development for SharePoint Online, I would rather recommend you to first go through one of my previous articles. This article will help you to setup development environment and get you started.

SharePoint Online: How To Install SharePoint Online Management Shell

Provide SharePoint Online Site credential when it is asked for

2

Operation: How To Get Lists Collection

3

In Step 1 we will initialize Web Object using SharePoint Client Context

In Step 2 we initialize SharePoint Lists Collection

In Step 3 we call the “Load” function to retrieve SharePoint List Collection properties from server

In Step 4 we call “ExecuteQuery” method to send the request to SharePoint Server

In Step 5 we iterate the lists collection returned back from the server and display required list properties as output

In Step 6 we call function that we have explained in Step 1-5

And here is the output for this operation

4.1

Operation: How To Add New List

4

In Step 1 we will initialize “ListCreationInformation” object which allows to specify the metadata details for this new list

In Step 2 we will specify Title for new list

In Step 3 we will specify Description for new list

In Step 4 we will specify List Template for new list. In this example we will use Custom List Template

In Step 5 we will call “Add” method of “Lists” collection for SharePoint Web

In Step 6 we will call “Load” method, to retrieve the properties of list object from Server

In Step 7 we call “ExecuteQuery” method to send the request to SharePoint Server

In Step 8 we call function that we have explained in Step 1-7

On successful execution of Step 1-7 we will get list added to SharePoint and Internal ID of list as Output

And here is the output for this operation

5

We can also see to the SharePoint Site to ensure that a new list has been added

67

Operation: How To Update Existing List

8

In Step 1 we will initialize “List” object which allows to modify the metadata details for this existing list

In Step 2 we will update the description of the existing list

In Step 3 we will call “Update” function of list object and then call “Load” method, to retrieve the properties of list object from Server

In Step 4 we call “ExecuteQuery” method to send the request to SharePoint Server

In Step 5 we will retrieve the list description to ensure that it is updated successfully

In Step 6 we call function that we have explained in Step 1-6

And here is the output for this operation

9

We can also see to the SharePoint Site to ensure that the list description has been updated

10

Operation: How To Delete Existing List

11

In Step 1 we will initialize “List” object by calling a method “GetByTitle” on the Web Object

In Step 2 we will call “DeleteObject” method on List Object that will delete the reference of respective list from lists collection

In Step 3 we call “ExecuteQuery” method to send the request to SharePoint Server

In Step 4 we will display success message to inform successfully deletion of the list

In Step 5 we call function that we have explained in Step 1-4

And here is the output for this operation

12

We can also see to the SharePoint Site to ensure that the list has been deleted successfully from SharePoint

13

That is all for this demo.

Stay tuned for the upcoming articles in this series.

Hope you find it helpful.

PowerShell Automation: How To Send Email with HTML Body Containing Inline Images

During of a recent assignment I get across an automation requirement to send formatted emails daily to a set of users.

The email content involved the HTML formatting with lot of images as a part of layout. I have appointed PowerShell as automation technology to get this done.

I found worth writing a small article to explain the code (which is interesting) to embed images with in outgoing email content.

Now to start with demo, say we have to send an email with Health of Weekly Sales Card for an online shopping store every week on Monday.

This email would look like the one in the following screen shot:

1

In Step 1,2,4 we are defining HTML that will be send as Email Content.

Here it is very important to notice the “SRC” Tag where we are specifying image path not as actual path but as a Content Identifier that is mapped to the path of the attachment added to the Email.

And this is the trick that you have to remember to get the images embedded into the html body of the email.

234

Now once we are done with defining body content for Email Body, we can start configuring SMTP Client and adding the attachments to the email

In Step 5 we will initialize “SMTP Server”, “Mail Message”, and “SMTP Client” Objects

In Step 6 configure “From” & “To” Email IDs for the intended recipients. Also specify the “Subject” & “Body” for the email

5

In Step 7 & 8 we will add attachments to the Email and provide each attachment a Content Identifier (remember we used this identifier in “SRC” Tag while defining HTML content for the body)

Attachments can be added to the email by using object of “Attachment” Class.

While initializing the “Attachment” Object we have to provide actual path of the attachment as input parameter

Then we have to make sure that

  1. “Inline” property should be set to “True”,
  2. “DispositionType” property should be set to “Inline”,
  3. “MediaType” property should be set to “<type of content, you are attaching>”,
  4. “ContentId” property should be set to any unique Content Identifier to represent the attachment uniquely

67

In Step 9 we will send the email by call in “Send” method of SMTP Client object. Make sure to dispose the “Attachments” & “Mail Message” objects

8

And finally we will call the Send-Email Function in Step 10 to run all the code snippets described earlier

9

That is all for this demo.

Hope you find it helpful.