Find all Lists and Libraries Where InfoPath is Used

Recently had the need to find and update most every InfoPath form in a production farm. This, mixed with the future demise of InfoPath, prompted the need to find or write a script. The below script will traverse every list and library in a given web app. The script can be easily modified to include every web app in a farm.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
                Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "C:\xsn-" + $(Get-Date -Format "yyyyMMddHHmmss") + ".csv"

$webApp = Get-SPWebApplication "http://webApp.sharepointed.com" 
"Title `t URL `t Type" | out-file $fileName

$(foreach($siteColl in $webApp.Sites)
{
                foreach($web in $siteColl.AllWebs)
                {
                foreach($list in $web.Lists) {                        
                
                                if ($list.BaseType -eq "DocumentLibrary" -and $list.BaseTemplate -eq "XMLForm"){
                                                "$($list.title) `t $($list.parentweb.url)$($list.DefaultViewUrl) `t Library" | out-file $fileName -Append 
                                                                
                                                
                                }elseif ($list.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"]){
                                
                                                "$($list.title) `t $($list.ParentWeb.URL)$($list.DefaultViewUrl) `t List" | out-file $fileName -Append
                                                
                                                }
												else{
												$check = 0
								foreach($c in $list.ContentTypes) {
												if($c.DocumentTemplateUrl.ToString().EndsWith("xsn") -eq $true)
												{
													$check++			
												}
												}
												if($check -gt 0)
												{
													"$($list.title) `t $($list.ParentWeb.URL)$($list.DefaultViewUrl) `t List" | out-file $fileName -Append
												}
												}
												}}})

PowerShell Unable to index into an object of type Microsoft.SharePoint.SPList.

Made a change to an existing PowerShell script, then ran into this error: Unable to index into an object of type Microsoft.SharePoint.SPList

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$web = Get-SPWeb "http://sharepointed.com/sitename"
$listTask = $web.Lists["My List"]
$sItem = $listTask.GetItemById(9)

$title = $listTask["Title"]

In the script, you will notice that I’m trying to capture the title of the item. The above script wasn’t working because I failed work with this list item, instead I was trying to work with the list object.

Correct script:

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$web = Get-SPWeb "http://sharepointed.com/sitename"
$listTask = $web.Lists["My List"]
$sItem = $listTask.GetItemById(9)

$title = $sItem["Title"]

copy.asmx This item is a copy of

Using the SharePoint Web Service Copy.asmx, you may notice this message on copied items: This item is a copy of

What I was doing wrong was, I used the destination URL in place of the source URL. If you provide a source URL, you will also receive the This item is a copy of… message in the properties view of the item. To avoid the message all together I replaced the source URL with the file name.

       //bad
       cWs.CopyIntoItems(destination, destinationUrl, fields.ToArray(), myBinary, out result);
       //good
       cWs.CopyIntoItems(filename, destinationUrl, fields.ToArray(), myBinary, out result);

CopyIntoItems.asmx

Error When Updating Item Using Web Service MoveNext

Using the SharePoint REST service to update items, ran into this error:

Unable to update the sharepoint document – An error occurred while processing this request.System.Data.Services.Client.DataServiceClientException: <?

xml version=”1.0″ …

…..

at System.Data.Services.Client.DataServiceContext.SaveResult.<HandleBatchResponse>d_1e.MoveNext()

The target list was set to require checkout before items could be updated.  Once I set require checkout to No, the REST service was able to update items.

 

Person or Group Field Append or Remove a Group

Using PowerShell I needed to append a group to a Person or Group field in a list.  The same logic should apply for adding or removing a user.

Append Group:



$web = Get-SPweb "http://sharepointed.com/sites/taco/"
$list = $web.lists["Good Tacos"]

$groupName = "Taco Eaters"
$group = $web.SiteGroups[$groupName]
$GroupValue = new-Object Microsoft.SharePoint.SPFieldUserValue($web,$group.id, $group.Name)

foreach ($item in $list.items)
 {
 $groups = $item["GroupsField"]

$groups.Add($GroupValue)

$item["GroupsField"] = $groups
 $item.Update()
 }

Remove Group:



$web = Get-SPweb "http://sharepointed.com/sites/taco/"
$list = $web.lists["Good Tacos"]

$groupName = "Taco Eaters"
$group = $web.SiteGroups[$groupName]
$GroupValue = new-Object Microsoft.SharePoint.SPFieldUserValue($web,$group.id, $group.Name)

foreach ($item in $list.items)
{
$groups = $item["GroupsField"]

<span style="line-height: 1.5em;">$groupRemove = $groups | ? { $_.LookupId -eq $GroupValue.LookupId }</span>

$groups.Remove($groupRemove)

$item["GroupsField"] = $groups
$item.Update()
}

Client machine making thousands of calls to SharePoint sites

——- Still researching this topic ——

Randomly each day, my computer was making thousands of calls to a couple SharePoint sites.  Using Fiddler, I could see that the calls were being made through WebDav.

User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7601

Then I notice that the first call of the batch was always to this web service:

/_vti_bin/publishedlinksservice.asmx

Googled around and found this post.  It’s related to SP2007 but it helped to find the answer.

http://blogs.msdn.com/b/jorman/archive/2009/07/30/my-sharepoint-sites-memberships-general-overview-on-how-this-functionality-works.aspx

After reading the post, I opened Word, clicked on File –>Save and Send –> Save to SharePoint.  There it was, all of the sites that my computer was reaching out to every day.  Taking things one more step deeper, I opened a document library, selected the Library tab in the ribbon, then selected Connect to Office.  From there select Manage SharePoint Sites.  Displayed was listed the libraries that I had created connections to.

http://mysite.yourdomain.com/_layouts/MyQuickLinks.aspx

All of the sites that are displayed in the Save to SharePoint section of Office are stored here:

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\Server Links\Published\My Site\

I deleted the My Site folder, opened Word and all of the sites were cleared out.

Also cleared out the following folder:

HKEY_Current_User\Software\Microsoft\Office\14.0\Common\Portal\Link Providers\

Next I need to make sure the folder doesn’t get repopulated with random sites!

Count the number of columns that contain a value

Say you have three columns that you want to find if a value exists in, then count the columns that contain that string.

In my list, I created three columns.

cOne, cTwo, cThree

All have a field type of single line of text.

Then I created a calculated column named cCalc.

The formula for cCalc is:

=COUNT(FIND(“Taco”,cOne),FIND(“Taco”,cTwo),FIND(“Taco”,cThree))

In my formula, I’m searching each field for the word Taco.  Keep an eye on your case usage.  Taco is not the same as taco.

Find function:

http://office.microsoft.com/en-us/sharepoint-server-help/find-function-HA001160996.aspx

Count function:

http://office.microsoft.com/en-us/windows-sharepoint-services-help/count-function-HA001160977.aspx

Office SharePoint Server Standard Site features must be enabled

In SharePoint Designer 2010, I was attempting to create an approval task for an item.  When I tried to added the action to the workflow, I received the following error.

Cannot insert this action. To use task process actions, the Office SharePoint Server Standard Site features must be enabled for this site by an administrator.

At the site and site collection I made sure SharePoint Server Standard Site features was enabled.  Taking it one step further, I also enabled SharePoint Server Enterprise Site features.  Still the workflow wasn’t working correctly.  Navigated back to the site collection features and activated the Workflows feature.  Refreshed SharePoint Designer and all of the actions worked.

Credit goes to Giles Hamson.

http://spandps.com/2012/04/03/spd-2010-cannot-insert-this-action-sp2010-sharepoint-ps2010-msproject-projectserver-in/

Does creating a folder start a workflow?

Does creating a folder cause a workflow to run?

Yes, when you create a folder, SharePoint treats it like you are uploading a new document.

If you only want to run a workflow on documents that are created or changed, you will need to add a step to your workflow.

The workflow condition would be:

If Current Item: Content Type equals Folder

Stop workflow

Doing this will stop the workflow each time a folder is added or changed.

 

Update users display name in SharePoint

The script below will allow you to change a users display name in SharePoint.


# add SharePoint snap-in if needed

 	$ntName = "domain\XXX"
	$displayName = "New Name"
 	$webApp = "http://webapp.sharepointed.com/"
	$user = Get-SPUser -web $webApp -Identity $ntName
	
	Get-SPWebApplication $webApp | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL | ForEach-Object {
		Set-SPUser -Identity $user -DisplayName $displayName -Web $_.URL
	}