MicrosoftSharePointWindows PowerShell

SharePoint Content Management using PowerShell | Dude! it’s a Due Diligence – Part 1

October-26-2015: Due to SharePoint tasks I missed MVP Summit 2015; Energy drained out due to disappointment!. So, I engaged 16 hours of my time with SharePoint team to perform a due diligence. Traveled in and around Netherlands for consultations with clients, developers and IT Professionals.

Introduction: Though we know each other we gathered at a party lounge for a friendly handshake and a BIER 🙂 and that’s Hertog Jan a typical Dutch Bier!



Not huge if we are four in numbers to share! – Cheers!!!

Challenge 1: Our security team will not allow us to install any third party components and products not guaranteed by Microsoft. So, we need to code to inventory of SharePoint farm(s). Includes MOSS 2007 & WSS 3.0,  SharePoint 2007 and SharePoint 2013.

Challenge 2: Developer team is busy in SharePoint Online training, we can engage them only twice a week.

Challenge 3: We need to plot a blue print of SharePoint farm without third party tools. The same needs to be shared with IT Managers before we design a plan for deployment or migrations or transformations.

🙂 🙂 🙂 Let’s keep the challenges apart. We may come across many while working on the Test and Production environment. So, we decided to get back to work on October-27-2015 with fresh mind! Yeah! we concluded not to work at home or not even to bing for solutions a day prior to work. A fresh mind is most important to work independently!

Requirement 1: Get all the items from Large List – We can see 30,000 + items we need a report in Excel.

I quickly showed the option in ribbon “Export to Excel” 🙂 “Assuming things will not help at work place!” Clients need Large List items reports to be shared in email and uploaded SharePoint portal. If it’s in portal why in email? To gain customer satisfaction we stopped asking questions, we gathered our tasks and grabbed a cup of coffee to our desk.


oops! That’s not a large list, it’s a Document Library enabled with Document Set! The complete web is built and deployed using custom code. Exploring is not a challenge but need to be handled it with care. Many columns are Interconnected or mapped with multiple lists in the same web.

CAML Query is SharePoint IT Professionals best friend, Just three things we need to do Query, Select Fields, and set Attributes to do this we need a tool; Indeed that will be PowerShell. The mission begins now!


Dude, that’s SharePoint 2010 hosted on Windows 2008 R2 Standard. PowerShell Version 2.0 🙂 🙂 🙂 – Developers Team looked at me and laughed – Do you remember this version? Can we raise a request to upgrade the version of PowerShell? (Nope! PowerShell 4.0 stable version requires some workaround in SharePoint box and PS 5.0 Product Preview is not stable version) shall we do a timer job? (No! No! No! – Folks, don;t forget MOSS 2007 we did many without Shell Mangement – Now, we have a tool to manage!. Go and Check your Visual Studio version and updates – I assume you may need one more Bier!)

Dusted up my old SharePoint script file and modified it as required

Step 1: Export – Items to CSV

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction 0
$spsite = Get-SPWeb -Identity
$splist = $spsite.Lists["Large List"]
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlquery = "<Where><Eq><FieldRef Name='FSObjType'></FieldRef><Value Type='Text'>1</Value></Eq></Where>"
$spQuery.Query = $camlQuery
$spQuery.ViewFields = [String]::Concat("<FieldRef Name='Project_Number'/><FieldRef Name='Created'/><FieldRef Name='Editor'/><FieldRef Name='Author'/><FieldRef Name='Number_of_downloads'/>")
$spQuery.ViewAttributes = [String]::Concat("Scope='RecursiveALL'")
$spQuery.ViewFieldsOnly = $true
$spListItems = $spList.GetItems($spQuery)
$collections = @()
Foreach($spListItem in $spListItems)
    $results = New-Object psobject -Property @{
    "Number" = $spListItem["Project_Number"]
    "Created By" = $spListItem["Author"].Split("#")[1]
    "Status" = $SPListItem.ModerationInformation.Status
    "Modified By" = ($spListItem["Editor"]).Split("#")[1]
    "Number of Downloads" = ($spListItem["Number_of_downloads"])
    $collections += $results 
$Collections #| Export-Clixml C:\temp\LargeList_Report.xml

Step 2: Send in email as attachment and close the requirement!

$param = @{
FROM = ""
TO = ""
Subject = "Large List Report"
SMTPServer = "SMTP Server"
Attachment = "C:\temp\LargeList_Report.csv"
Send-MailMessage @param

Requirement 2: We have removed the existing Approval Workflow and lost the track of Content Approved Items – We can get that in search result.

Yes, this time no SharePoint Shell Management, kicked on Windows PowerShell 5.0 Product Preview from my local machine and got the report. Lucky me! the SharePoint document library will not allow duplicate items 🙂 so, search results returns one URL (customized search page!) and team didn’t reset the Search Index 🙂 “25% of the tasks completed – Yes, users can search and read contents from the application

The items found in search results URL will be re-processed : Set Content Approval to $true 🙂

(Get-Content C:\Temp\Large_list.csv).Foreach({
(Invoke-WebRequest -Uri "$_" -UseDefaultCredentials | 
Select -ExpandProperty Links).href | Select -Last 1

Requirement 3: Approve all documents – No need to think about the tasks which are already fired. So, concluded to change moderation status information to approved for the items found in search result.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction 0
$web = Get-SPWeb -Identity ''
$list = $web.Lists["Large List"]
$ids = Get-Content C:\Temp\Approved_Id.txt 
foreach($id in $ids)
    $item = $list.GetItemById($id)
    $item.ModerationInformation.Status = "Approved"
    "Approving Project {0} - Status: {1}" -F ($item["Project_Number"] , $item.ModerationInformation.Status)

Content mangers did a sanity checks and confirmed all set to good! So, it’s time for us to deploy new (or) upgraded solution. Moved to look at developer team. Oops! really pity – a laptop with 4 GB RAM running Visual Studio 2010 in SharePoint Development environment.


It’s lunch time 🙂 🙂 🙂 we have few more fun to flow in! Gained energy with BitterBal


Continued discussion with development at lunch and assessed the challenges – We discussed about buying some more time 🙁 “My Mind voice: I could have been to MVP Summit 2015!”. That was just a discussion not a conclusion; Post lunch we were back at desk to continue content management automation.

I requested developer to ignore all exiting 🙂 DOC LIB items and automation tasks. So, they can develop ASP.NET form to map with DOC LIB columns – Yayyyyyy! Now we have Metadata Columns in the library! – Need a coffee! 🙂

Requirement 4: Deploy the new solutions – Yep deploying new WSP! One liner using PowerShell – Deployment went fine and development team signed off (Will be back into production support as required), But Application didn’t turned up well!

It’s time for us to show the Power of Shell 🙂 🙂 🙂

I expected the below shiny error 🙂 But I should explain this to IT Managers like “sorry, we are encountering an unexpected error


🙂 Woot! Go ! Open up SharePoint Management Shell and execute the below piece of code with start and end time parameters – Pipe and fetch the correlation ID. It’s that simple!

Start Time : Grab it from the error screen shot

End Time : Just increase by 1 minute or 2 (Assumption!)

Get-SPLogEvent -StartTime "05/11/2015 11:22:08" -EndTime "05/11/2015 11:23:08" | Where-Object 
{$_.Correlation -eq "8a343106-0d90-492f-a683-dd0fb59c0058"}

“Missing LCID for <Column>” 🙂 he he he. Missing English and French!

New solution includes new fields which is set to be mandatory; managed term store now need two more language English and French – Dutch is by default!

Okay, I had the service packs binaries so installed English and French Language Packs to confirm the fix- Voila! we were back on track – 45% of the tasks accomplished! Note: If you are in RTM – Download the latest service pack – Extract and Delete any entries in Update folder which is in the year 2013. So, you can install the SharePoint 2010 Service Packs as RTM and upgrade to the current farm build version id required.

We have done only the initial phase of the work. Few more SharePoint 2010 IT Professional tasks are shared below

  1. Update all missing fields.
    • How to find the missing fields? We may have newly added columns 🙂
  2. Read other list and update the DOC LIB.
    • Dude! it’s Note Field so we have HTML tags Export and Import in PowerShell or editing in DOC LIB using data sheet looks ugly 🙁
  3. Approve all the approved items in the DOC LIB.
    • After manipulating the items – Approve the items if it was approved and pending should remain as pending. 🙂 We haven’t touched workflow
  4. Most of the information are rendering in SharePoint portal by reading Active Directory.
    • Few users left the organization – We need to update author names with common ID (This is interesting 🙂 )
  5. What happened to LYNC Presence in the SharePoint portal? LYNC Client is upgraded to Skype for Business. Need to investigate further more! May be browser add in!
    • Not my cup of tea though still I will figure out the reason!
  6. Who created the item? Who Modified the same?
    • We sorted this – But will discuss this again!
  7. Read the department of author and update it in the DOC LIB field (This is very interesting task because we need to explore User Profile Service Application)
  8. Complete the content automation – After all set to good we will start the due diligence for migrate the farm to SharePoint 2013. Or, will think about a POC using SharePoint 2016 Technical Preview!
    • I am waiting ! Not, that easy but possible!
  9. Mean while we need to upgrade the Operating System of MOSS 2007 – Since Windows 2003 server has no support we need to upgrade it to Windows 2008 R2 Standard and strictly needs to be in 32 bit.

More real time scripts, SharePoint Developer and IT Professional discussion about PowerShell will be continued in next blog 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *