Use PowerShell to Export a List of My Sites

How many My Sites (MySites) are currently enabled in my Farm?

if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPsite "http://mysite.sharepointed.com/"
$spWebApp = $site.WebApplication

$log = "c:\test.txt"

foreach($site in $spWebApp.Sites)
{
    $site.url |	Out-File $log -Append
    $site.Dispose()
}

load the powershell snapin.
get the Web App hosting your My Sites.
set a variable to where you want the script to output the results to.
loop through all the sites in the Web App, and output them to your text file.

People search not working

The People scope in Central Administration was showing 0 ( zero ) items, but my Number of User Profiles in Manage Profile Services was showing plenty of profiles.

First I looked at the scope to make sure it was correct.

Scope Rule Type: Property Query

Property Query: urn:content-class:SPSPeople 

Behavior: Include

Next, I looked at the User Profile Service (Central Admin –> Manage Service Applications) or (http://yourCentalAdminURL/_admin/ServiceApplications.aspx).  I wanted to make sure the same account that was crawling all my data had access to this service.   Select the first User Profile Service item, then click on Administrators in the ribbon.  Your Default content access account should be listed here with Retrieve People Data for Search Crawls permissions.

If your Default content access account is not listed in the Administrators list, add the account and give it Retrieve People Data for Search Crawls permissions.

Where I can find my Default content access account?

Central Administration –> Manage service applications (under Application Management) –> click on Search Service Application.  There you should see your System Status web part, and listed will be Default content access account.

my sharepoint is slow

Recently received an email from a user that basically said “my SharePoint is slow.”

The user sent me a link to the Form Library they were working with.  I clicked on link and it took roughly two minutes for the page to open.  Long story short, the user had changed to View to display 2,000 items at a time.

I updated the View to return 50 items, and now “my SharePoint is fast.”

 

CAML Query Returning all Records

I was trying to CAML query a document library, but my returned data set had all the items from the library.

Bad query:


$camlQuery = '<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Text">1624</Value></Eq></Where></Query>'

Good query:


$camlQuery = '<Where><Eq><FieldRef Name="ID" /><Value Type="Text">1624</Value></Eq></Where>'

Removing <query> and </query> from the string fixed the CAML query.

The Process cannot access the file because it is being used by another process

Central Admin won’t load…

After rebooting my farm I wasn’t able to access Central Administration.

Went into IIS and noticed the site was stopped.  When I tried to start it, I was greeted with the following error: The Process cannot access the file because it is being used by another process.

On the server hosting the site, get to a command prompt and type:  netstat -ano

scroll through the list and find the port that Central Admin is using.  After you find it, make note of the PID (right column).

Now, open task manager, click on the Processes tab.  From the View menu, click on Selected Column… Select PID (Process Identifier).

Sort the PID column in Task Manager, locate the PID that you made note of in the command window.  Kill the process.

Go back to IIS, start the Site (right click on the site, Manage Web Site, Start).

Browse to Central Admin!

Mass Create Word Documents Using PowerShell

I’m my other post,  I outlined how to create a bunch of folders in a Document Library.  In this post, I’ll explain how I then populated those folders with Word documents.

To stage this, I created a Document Library called BaseLibrary.  In BaseLibrary I uploaded a single Word document.  After uploading the document, make note of the ID of the document in the Library.  *To get the ID of the document, modify your default View, and add the ID column, click save.*


if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPweb "http://sharepointed.com/taco"

$spListFrom = $site.lists["BaseLibrary"]
$iFrom = $spListFrom.GetItemById("1")

$mList=$site.Lists["Shared Documents"]

foreach($f in $mlist.Folders)
 {

$fName=$f.Name

$range = 1..500
 $count = $range.Count
 for($i=0; $i -lt $count; $i++)
 {
 $nName = "$fName$i.docx"
 $nURL = $site.Url+''+$f.Url+"/"+$nName
 $iFrom.CopyTo($nURL)
 }
 }

$site.dispose()

What I’m doing here is referencing the document with the ID of 1, from BaseLibrary.

Loop through all the folders in Shared Documents, in each folder, I’m doing a loop to copy the document into the folder, and create a new name for the document on each loop.

$nName = “$fName$i.docx”

$fname is the name of the folder we are working with.

$i is the count of the loop we are on.  Joining the two variables will create a unique file name.

$range = 1..500

To create more or less documents in each folder, adjust this range.  This example will create 500 documents in each folder.

use PowerShell to create a bunch of folders

I’m going to explain this idea in two posts.  This post will outline creating a bunch of folders in a Document Library.  After the folders are created, I will then demonstrate how to put a bunch of Word documents in the newly created folders.

Why?

I was needing a way to stress test / performance test updating documents in SharePoint.


if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPweb "http://sharepointed.com/taco/"
$mList = $site.Lists["Shared Documents"]

$range = 1..1000

$count = $range.Count
for($i=0; $i -lt $count; $i++)
 {
 $spFolder = $mList.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$i)
 $spFolder.Update()
 }

$site.dispose()

$range can be adjusted to create less or more folders.  If you only wanted to create ten folders, change $range = 1..10

I’m using the incremented value of $i to name the folders. You can setup a another naming convention for the foldering.

In the next post, I will populate the folders with a Word document.

Use PowerShell to Loop Through Folders in a Library

Here is an example of using PowerShell to look through folders in a SharePoint Document Library.


if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
      Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPweb "http://sharepointed.com/site/taco/"

$mList=$site.Lists["Shared Tacos"]

foreach($f in $mlist.Folders)
 {
 Write-Host $f.Name
 }

$site.dispose()

The item is currently locked for editing. Waiting for item to be checked in or for the lock to be released

Workflow error:

The item is currently locked for editing. Waiting for item to be checked in or for the lock to be released.

Working with SharePoint Designer 2010 and InfoPath, I created a workflow to perform an Action once a form was submitted or changed.

The error above was stopping the workflow from running any of the Steps / Actions.

The fix was to add a Wait for Change in Document Check-Out Status Action to the workflow.  This Action should be the first item executed in the workflow.

The item is currently locked for editing

The item is currently locked for editing

Why does this happen?  Assume the workflow is being triggered the millisecond that the form is being written to the library and not waiting for all the data to finish writing.

*Note* Once the form/item is unlocked, it might take a few minutes for the workflow timer to process the item.

PowerShell Get URL of SharePoint List or Library

How do you get the URL of a SharePoint List or Library?

I had hoped it was as simple as $List.URL or something close to that.

Here is how I solved it, and please let me know if you have a better way!


Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$site = Get-SPweb "http://sharepointed.com/sites/blah"

$mList=$site.Lists["Tacos"]
 $ListURL = $site.url +"/"+ $mList.RootFolder.Url

$site.Dispose()

Update
Found a weird issue when trying to use $ListURL in a href tag. For some reason, if the list name had a space in it, anything after the first word would be dropped off in the link URL.

Example:
List Name: Real Big Taco
URL in href would be http://sharepointed.com/sites/blah/lists/Real

My fix:

 $ListURL = $site.url +"/"+ $mList.RootFolder.Url.ServerRelativeUrl.Replace(" ","%20")

Or as amac44 pointed out:
$list.ParentWeb.Url + ‘/’ + $list.RootFolder.Url