Master PowerShell Script to Check Changes in SharePoint

As I explained in multiple blog posts in the past, every second tuesday of the month, whenever Microsoft releases their SharePoint 2013 Cumulative Updates, I go ahead and install them on my dev environments. The first thing I do afterward is run a custom PowerShell script I have developped myself, get information about the various PowerShell cmdlets, and Object Model properties exposed by my environment, and compare that list with the list from the previous month. Then, using a comparison tool such as WinMerge, I check for the difference between what was available in the previous month compared to what is now available after applying the new Cumulative Update. Today I decided to share my script with you guys in order for you to better understand how I go about determining if Microsoft introduced any new goodies with their update packages. The following script is what I run on my local server every month after installing the latest SharePoint 2013 Cumulative Update:

Add-PSSnapin Microsoft.SharePoint.PowerShell

$fileContent = “—- PowerShell Cmdlets —-`r`n”

$powerShellCmdlets = Get-Command | Where{$_.ModuleName -eq “Microsoft.SharePoint.PowerShell”}

foreach($cmdlet in $powerShellCmdlets)
{
$fileContent += $cmdlet.Name + “`r`n”

}

$fileContent += “`r`n—- SPFarm —-`r`n”

$farm = Get-SPFarm

$members = $farm | Get-Member 

foreach($member in $members){
$fileContent += $member.Name + “`r`n” 

}

$fileContent += “`r`n—- SPWebApplication —-`r`n”

$webApp = Get-SPWebApplication

$members = $webApp | Get-Member

foreach($member in $members)

$fileContent += $member.Name + “`r`n” 

}

$fileContent += “`r`n—- SPSite —-`r`n”

$site = Get-SPSite http://localhost

$members = $site | Get-Member

foreach($member in $members){

$fileContent += $member.Name + “`r`n”
}
$fileContent += “`r`n—- SPWeb —-`r`n”
$web = Get-SPWeb http://localhost
$members = $web | Get-Member

foreach($member in $members)
{
$fileContent+= $member.Name + “`r`n”
}

$fileContent += “`r`n—- SPList —-`r`n”

$lists = $web.Lists

$list = $lists[2]

$members = $list | Get-Member

foreach($member in $members)
{
$fileContent += $member.Name + “`r`n”
}

$fileContent += “`r`n—- SPView —-`r`n”

$views = $list.Views

$view = $views[0]

$members = $view | Get-Member

foreach($member in $members){
$fileContent += $member.Name + “`r`n”

}

$fileContent += “`r`n—- SPListItem —-`r`n”

$items = $list.Items

$item = $items[0]

$members = $item | Get-Member

foreach($member in $members)

{
$fileContent += $member.Name +“`r`n”
}

$fileContent += “`r`n—- SPContentDatabase —-`r`n”

$contentDB = Get-SPContentDatabase

$members = $contentDB | Get-Member

foreach($member in $members){
$fileContent += $member.Name + “`r`n” 

}

$fileContent += “`r`n—- SPServiceApplication —-`r`n”

$service = Get-SPServiceApplication

$members = $service[0] | Get-Member

foreach($member in $members){
$fileContent += $member.Name + “`r`n”
}

$fileContent | Out-File “C:\CU\Current.txt”

What my script does is the following:

  •  Get a full list of all PowerShell cmdlets contained in the Microsoft.SharePoint.PowerShell module;
  • Get all properties and methods on the following objects based on the SharePoint Object Model:
    • SPFarm
    • SPWebApplication
    • SPSite
    • SPWeb
    • SPList
    • SPListItem
    • SPView
    • SPServiceApplication
    • SPContentDatabase

Then it writes the resulting list in a text file on disk, in my case under c:\CU\Current.txt.

Microsoft Premier Field Engineer – SharePoint

Leave a Comment

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

*
*