After working on my last post, I found that I also needed a version of my script for SharePoint 2007. Where I work I still have a number of farms on 2007 and some may not go away for the next year or more. To save time and get to my goal of automation, I worked through a couple of days worth of trying to get all the same functionality into a script that will gather the necessary data from my SharePoint 2007 boxes. Listed below is the script. Some of the lines didn’t scale really well in blog post format, so I pushed cut the line and indented. I would cut and past back into your text editor of choice and pull the lines back together as I never tested to see if it would work multi-line. Since this isn’t c#, it probably wont.
#Get all the web applications in the farm #This script has been cobbled together using many sources including: #http://sharepointpsscripts.codeplex.com/ - Content DB Info Gathering #Load necessary DLLs [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") #Functin to get the local farm object function global:Get-SPFarm{ return [Microsoft.SharePoint.Administration.SPFarm]::Local } #Function to get all of the web applications in the local farm function global:Get-SPWebApplication{ Get-SPFarm |% {$_.Services} | where {'$_.TYPEName -eq "Windows SharePoint Services Web Application"'} |% {$_.WebApplications} |% {Write-Output $_} } #Get all the web applications in the farm $webapps = Get-SPWebApplication #Declare the files we will write to $appFile = "AppInfo.csv" $dbFile = "DBInfo.csv" $urlFile = "URLInfo.csv" #Declare variables $portal = "Corp" $env = "Production" $version = "2007" #Declare the properties we will need to get database information later $DBName = [Microsoft.SharePoint.Administration.SPContentDatabase]. GetProperty("Name") $DBSiteCount = [Microsoft.SharePoint.Administration.SPContentDatabase]. GetProperty("CurrentSiteCount") $DBWarningSiteCount = [Microsoft.SharePoint.Administration. SPContentDatabase].GetProperty("WarningSiteCount") $DBMaximumSiteCount = [Microsoft.SharePoint.Administration. SPContentDatabase].GetProperty("MaximumSiteCount") $DBIsReadOnly = [Microsoft.SharePoint.Administration. SPContentDatabase].GetProperty("IsReadOnly") #Create the header row for the CSV files Add-Content -Path $appFile -Value "WebApplication,URL,Version,Portal, Environment" Add-Content -Path $dbFile -Value "Name,CurrentSiteCount,Status, WarningSiteCount,MaximumSiteCountWebApplication,Portal,Production" Add-Content -Path $urlFile -Value "URL,WebApplication,Portal" #Loop though each web app foreach($webapp in $webapps){ #Get root URL - required because properties are different in 2007 than 2010 $url = ($webapp.alternateurls | ? {$_.urlzone -eq "Default" }).incomingurl #Add information about the web application Add-Content -Path $appFile -Value "$($webapp.Name),$($url),$($version), $($portal),$($env)" #Loop through all the content databases in this web application foreach($db in $webapp.ContentDatabases) { #Get all the properties needed $CurrentDBName = $DBName.GetValue($db, $null) $CurrentSiteCount = $DBSiteCount.GetValue($db, $null) $CurrentMaximumSiteCount = $DBMaximumSiteCount.GetValue($db, $null) $CurrentWarningSiteCount = $DBWarningSiteCount.GetValue($db, $null) $CurrentStatus = $DBIsReadOnly.GetValue($db, $null) #Change the status property to reflect the 2010 style if($CurrentStatus -eq $false){ $Status = "Online" } else { $Status = "Disabled" } #Add information about each database Add-Content -Path $dbFile -Value "$($CurrentDBName), $($CurrentSiteCount),$($Status),$($CurrentWarningSiteCount), $($CurrentMaximumSiteCount),$($webapp.Name),$portal" } #Loop through all site collections in web application foreach($site in $webapp.Sites) { Add-Content -Path $urlFile -Value "$($site.URL),$($webapp.Name), $portal" } }
As always, it you have problems, questions or comments feel free to drop me a line.
