How can I get list of users which have their own documents stored in My Sites (MOSS 2007)? Or even better, all their documents together with names? It dosen't matter if it will be via script or GUI. I just know that we have some users with documents in old portal and I must transfer it somehow to the new My Sites on SP 2010. Thank you.

1 Answer 1


I would create a powershell script that loops through all the user profiles. Retrieves the PersonalSite of that user and list the files that reside in a certain document library. The script below should be able to list the URL of all the files that are inside the document libraries 'Personal Documents' and 'Shared Documents'.

#Load the required SharePoint DLL's for this script

$siteUrl = "http://yourdomain"
$documentLibrariesToScan = "Personal Documents", "Shared Documents"

#Get the UserProfileManager
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$serverContext = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$userProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serverContext)

foreach($userProfile in $userProfileManager) 
    Write-Host $userProfile["AccountName"]

    #Get the personal site of the user. 
    $personalSite = $userProfile.PersonalSite
    if($personalSite -ne $NULL)
        foreach($documentLibraryName in $documentLibrariesToScan)
            #Check the specified document libraries.
            $documentLibrary = $personalSite.RootWeb.Lists[$documentLibraryName]

            if($documentLibrary -ne $NULL)
                foreach($item in $documentLibrary.Items)
                    #Write all the urls of the files found in the document library.
                    Write-Host $item.File.Url
  • I'm sorry, I'm not able to run this script. If I substitute variables with almost everything that come to my mind, I get only "web application could not be found" error. Address in what form must be typed in please?
    – Molik
    Aug 9, 2011 at 13:40
  • You should use the address of your SharePoint site, so not your SSP. If it runs on a specific port then also add that, like 'http: //your.domain.com:54321>'. It will create an SPSite object and retrieve the the SSP / UserProfileManager that is used for the SPSite. Aug 10, 2011 at 7:06
  • > It works! The trick was to run this script on the right server. My apologies, I tried to run it from our maintenance server with administration & migration tools all the time. Thank you!
    – Molik
    Aug 18, 2011 at 7:25
  • The only one thing, script listed only public (shared) documents, can I somehow get all docs in libraries please ? Some users have "Unable to index into an object of type Microsoft.SharePoint.SPListCollection" error in log, is it possible, that they have another library with another documents beside the shared ones ?
    – Molik
    Aug 18, 2011 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.