So You Say You Want an Upgrade?

by sharepointbitme

Today I am going to upgrade my pre-upgrade script. Nothing too dramatic and there are still plenty of ugly constructions in it that I refuse to touch for fear that I will lose months of my life polishing the details.

The major changes are redirecting the output within the script (see my previous entry about that) and adding an option to list all the webs hosted in the farm and listing what template they use. This can be really helpful in finding where missing templates may cause things to break. Like the Fab 40 templates, still, in 2014, *sigh*.

 

# Please login to your SharePoint server using an account that has permissions to run PowerShell Commands.
# Place the file InfoScript.txt into a directory on the server that hosts SharePoint Central Administration and rename it to InfoScript.ps1
# Open the SharePoint 2010 Management Shell and type:
# c:[directory where you placed the script]InfoScript2010.ps1
# The "Out-File -width 200" part of the command is to make the output wider to fit more information on each line
# Once the script has completed, please forward the output to your Rackspace contact via email.
#|
#

add-pssnapin microsoft.sharepoint.powershell -ea 0


function OutRedirect
{

$scriptuser = whoami
write-output "InfoScript was run under account name","------------------------------------", $scriptuser 

write-output "Servers in farm, their upgrade status and version number (version is just for comparison)"
# Added bit to weed out SQL and email servers
Get-SPServer | Where-Object { $_.role -ne "invalid" } | Select Name, Role, NeedsUpgrade, Version | out-string -width 200
write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Web Apps in Farm and if they are using claims auth or not"

Get-SPWebApplication |select DisplayName, URL, @{Label = "Claims Enabled?"; Expression = {$_.UseClaimsAuthentication}} |out-string -width 200

write-output "SharePoint Farm Build number"
Get-SPFarm | Select BuildVersion | out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Solutions in Farm"
Get-SPSolution | select Displayname, deployed, DeployedWebApplications | out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Site Collections by DB"
Get-SPContentDatabase | %{Write-Output "`nDatabase: $($_.Name)"; ForEach($site in $_.sites){write-Output ("`t " + $site.url)}}| out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Database sizes"
Get-SPDatabase |Sort Name| select Name, @{Label = "DB Size in MB"; Expression = {"{0:N2} MB" -f ($_.DiskSizeRequired/1MB)}}, Type, Id | out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "SiteCollection size estimates (very rough)"
Get-SPSite | Select URL, @{Label="Storage"; Expression={"{0:N2} MB" -f ($_.Usage.Storage/1048576)}} | out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "AAM Info"
Get-SPAlternateURL 
write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Features in Farm"
Get-SPFeature -Limit all | out-string -width 200

write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Templates in Farm"

Get-SPWebTemplate | out-string -width 200


write-output ""
write-output "--------------------------------------------------------------------------------------------------------"
write-output "Template USED in farm by web" " "

Write-Host -foregroundcolor yellow "The final step in this script will list every web (site or subsite)
in your farm along with the template used by that web.
 
If you have a large number of sites it might take some time to complete and use a lot of resources. 

All the other information collected by this script has already been placed in a file,
so if you answer no, only this step will be skipped."

$continue = Read-Host "Would you like to continue? (Y/N)"
if($continue -eq "Y")
{
get-spsite -limit all | get-spweb -limit all |select URL, @{Label = "Template"; Expression = { $_.WebTemplate}}, @{Label = "TemplateID"; Expression = { $_.WebTemplateID}} | out-string -width 200
}
}

$OutFile = Read-Host "Please enter the path (name you want for the file included) (ex. C:tempInfoOutput.txt)"
outRedirect|Out-File -width 200 $OutFile

Enjoy and have a happy holiday season!

Advertisements