Friday, November 23, 2007

Print out STS Site Taxonomy

Yes, that does say STS...ugghhhh. I was asked by a customer to get a list of all of the sites in their SharePoint Team Services 1.0 environment. I quickly ran into a wall finding any kind of documentation, API or even attempting to comb through the database. Since STS stores all of its files on the filesystem, I decided to traverse the file system and see if I could determine if a folder was a site folder. After some trial and error I think I pretty much determined the conditions. So then I resorted to good ole VBS to get me the data. So here is a VBS script that you can use to traverse your STS structure and print out which folders are sites.



Option Explicit
'-------------------------------------------------------------------------------
'
' Traverses STS Structure and finds all Sites and determines if site is stale
' Written by: Pirooz Javan
' Create Date: 08/21/2007
'
' Description:
' This script looks for files in a source directory that are meet a
' specified criteria that permits them to be moved to a destination
' directory. The existing criteria is that the file must be older
' than 30 days from the current data and the file's data created
' attribute
'
'-------------------------------------------------------------------------------
Const ForReading = 1
Const ForWriting = 2
Const SourceFolder = "root"

Dim StaleDate
Dim SearchString

StaleDate = "2006"
SearchString = "title id=onetidTitle>Home"

Dim objFSO, objWSH
Dim index
Dim m_log

index = 1

Set objWSH = WScript.CreateObject ("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set m_log = objFSO.CreateTextFile("STS-Sites.Log")

TraverseFolder index, objWSH.ExpandEnvironmentStrings(SourceFolder)

Function TraverseFolder (idx, SourceFolder)
Dim m_Folder, m_SubFolders
Dim m_Files, m_SubFolders2
Dim bApp

Set m_Folder = objFSO.GetFolder(SourceFolder)
Set m_SubFolders = m_Folder.SubFolders

If isFolderSTSApp(m_Folder) Then
bApp = True
m_log.WriteLine m_Folder.path
End If

For Each m_Files In m_Folder.Files
' If bApp And (cint(Year(m_Files.DateLastModified)) < cint(StaleDate)) Then
' m_log.WriteLine "*****Folder " + m_SubFolders2.Name + " is a STALE STS APP"
' End If
' m_Log.WriteLine m_Folder.path + "\" + m_Files.name + Chr(9) + cstr(m_Files.DateLastModified) + Chr(9) + cstr(m_Files.Size)
Next
For Each m_SubFolders2 In m_SubFolders
' m_log.WriteLine SourceFolder + "\" + m_SubFolders2.name + Chr(9) + cstr(m_SubFolders2.DateLastModified)
Call TraverseFolder (idx+1, SourceFolder + "\" + m_SubFolders2.name)
Next

Set m_Folder = Nothing
Set m_SubFolders = Nothing
End Function

Function isFolderSTSApp(folder)
If objFSO.FolderExists(folder.path + "/_layouts") AND objFSO.FolderExists(folder.path + "/_private") Then
isFolderSTSApp = True
Else
isFolderSTSApp = False
End If
End Function

Function isHomePageFile(filePath)
Dim ReadFile, thisTXT, ValueSearch

Set ReadFile = objFSO.OpenTextFile(filePath, ForReading)
thisTXT = ReadFile.ReadAll
ValueSearch = InStr(1,thisTXT,SearchString,1)

If ValueSearch>=1 Then
isHomePageFile = True
Else
isHomePageFile = False
end If

ReadFile.Close
Set ReadFile = Nothing
End Function

m_log.Close
Set m_Log = Nothing
WScript.Quit(0)