Get Web Sites Owners Listing (Powershell to Text File)

I created this script to gather a listing of web site owners within a Site Collection.  It has been set to only gather the first tier of sites.  If you wish to go deeper, change the comparision.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
function IterateSubSites ([Microsoft.SPWeb]$subSite)
    if ($subSite -ne $null)
        if($subSite.Webs -ne $null)
            foreach($subsites in $subSite.Webs)
$webApplicationURL = ""
$webApp = Get-SPWebApplication $webApplicationURL
foreach($site in $webApp.Sites)
    foreach($subWeb in $site.AllWebs)
       if(($subWeb.Url.Split("/") | measure-object).Count -lt 5)
        $output += $subWeb.Url + "`r`n`r`n"
        foreach($group in $subWeb.Groups)
            if($group.Name -like "*Owners*")
                $output += "Owner(s): " + "`r`n`r`n"
                foreach($user in $group.Users)
                {$output += $user.Name + " - " + $user.Email + "`r`n`r`n"; }
    if($subWeb.IsRootWeb -ne $true)
$output | Out-File "C:\owners.txt" 

Automatically Filing SharePoint Documents After Timespan

1) Set up a Document Library that will house the “temporary” documents (ie. the documents that you plan on having automatically filed).  For instance “New Documents.”

2) Then set up a separate “Custom” list that you will use as your routing list.  In this list enter all the names of the various other document libraries that you want to file your documents to.  For instance “Tax Records” and “Property Records.”


3) Go back to your “New Documents” library that you just created, and add a new column under “Document Library Settings.”  Give it a content type of “Lookup”, and tie it to the list you created in step 2.  Call it “Filing Location.”  *This can also be done with metadata if you have it enabled.


4) Now that you have your infrastructure set up, it is time to create a workflow to automatically file the documents.  Open SharePoint Designer, and browse to your site. Choose to create a new workflow.

5) Link the workflow to your “New Documents” library.  Choose to activate the workflow whenever a new item is added. Enter the workflow steps in the following format:

  • Choosing to examine the “Filing Location” column.
  • If it matches one of the types you identify, choose to pause it for the time you desire to have it displayed in the “New Documents” library.  In this case, I will choose 5 days.
  • Then have the workflow copy the document (“Current Item”) to the desired matching document library.


6) Repeat the previous step as many times as is necessary for the different document libraries you wish to file your documents to.

7) Finally, for the last step, choose to examine the file, and then pause it for a time period greater than the time you chose for step 5. Then add an instruction to delete the item after that time has passed.


8) Save the workflow.

9) Now when you add documents to the “New Documents” folder, they will be automatically filed.  However, when you upload them, you will also need to choose where they get filed under the “Filing Locations.”


How To Create A “Private” SharePoint Discussion Board

One of the requests I hear most from users is for the ability to create a private discussion board on their site.  They have a general user base, but want to lock down a particular SharePoint discussion board to just a small subset of users.  Unfortunately, there is no really obvious way to do this, so creating a “private” discussion board is a multi-step process.


The benefits to creating a private discussion board are numerous.  It can allow you to have a central location for having secure communication between team members, as well as provide the ability to share documents, all while remaining within the context of a parent site.  Typically, site admins would prefer to keep users on a single site, rather than go off and create subsites for all the different user sub-groups that want their own private area.  Private discussion boards are a great option for this.

To help those that might want to create one on their site, but not know where to start, I put together this little guide to help you create one.  While these screenshots are for SharePoint 2010, the same steps will also apply to SharePoint 2013, since the discussions list has remained essentially unchanged.

1) Go To “Site Actions”, click on “More Options…” You can also get to this menu by clicking “Create” when on the “Discussions” tab.

2) Choose “Discussion Board” as the type. If you do not wish to have this on the navigation, do NOT click “OK” just yet.


3) (optional) Click “More Options”. Enter the name of the private board. For Navigation, choose “No.” Then click OK.


4) Once the board is created, you will need to modify the permissions to make it a private board. Click on “List Permissions.”


5) THIS IS THE MOST IMPORTANT PART. **** DO NOT CLICK MANAGE PARENT **** If you change the permissions of the parent, you will mess up the permissions for the entire website.

Instead, click on “Stop Inheriting Permissions”


6) Remove all the groups and users, except for the “Owners” group for the website. Click OK.


7) Go to “Site Actions”, “Site Permissions”


8) Create a new group for the private board (this step may be unnecessary if you already have a SharePoint group you wish to use)


9) Give the group a name and set it to “Read Only”. *This does not mean it will be Read Only for the discussion board, it means it is a read only group for the site. If they have permissions that are elevated for the site, those will be taken care of by another group they are a member of. This group is just for the private board.


10) Click “Create.” Once you complete this step, add the users or AD groups to the SharePoint group that need permission.

11) Click “Site Actions”, “View All Site Content”

12) Click on the private discussion board you just created


13) Click “List Permissions” and then “Grant Permissions”

14) Use the people picker to find the group that you just created.


15) Set the permission for the group as they relate to the private board. Typically “Contribute”, if it is an admin group set it to “Full Control”


16) Verify the permissions

17) Next we want to add a link to the private board. Go to “Site Actions” click on “Site Settings”

18) Click on “Navigation”

19) If you have a private discussions tab, click that, then click “Add Link”

20) Give it a title and browse for the private board to create the link.


22) Click OK, and check to see if the link appears.

23) (optional) Finally, if you created a group at the beginning, go into the group and add the members you want to grant access.  Click “Site Settings”, “Site Permissions”, and add users to the group.


Moving the Search Service Application to a Different Farm Server

For performance reasons, you may wish to move the Search Service Application in SharePoint 2013 to a different farm server. After adding the server to the farm, and provisioning the Search Service, in order to move the service, you will need to do so through Powershell, as that is the only way to get the components moved over.

Rather than breaking up the SSA components onto multiple servers, to reduce lag, etc. between servers, its suggested to keep the components together on the same server.


So for instance, you may have Central Admin running on Server A, along with the User Sync and Search. To reduce the load on Server A, you may want to move the entire search portion over to Server B.

To do so, run the following commands:

$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
$newSrv = Get-SPEnterpriseSearchServiceInstance -Identity <<Server B Name>>
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $newSrv
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $newSrv
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $newSrv
New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $newSrv
New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $newSrv
New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $newSrv -IndexPartition 0
Start-SPEnterpriseSearchServiceInstance -Identity $newSrv
Set-SPEnterpriseSearchTopology -Identity $clone

Next, you will need to re-clone it again to remove the old components off the old server

$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active

Run the following, this will give you a list of all the component IDs you will need to remove them from Server A

Get-SPEnterpriseSearchComponent -SearchTopology $clone

Replace the IDs in the following commands:

Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Remove-SPEnterpriseSearchComponent -Identity <<Server A Component ID>> -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone

Run a refresh in central admin, and you should see the following:


Using CQWP To Show Discussion Rollup with Reply Count and Last Update Date

This is what we want our final result to look like:


1) Add a Content Query Web Part to your page.  Go in and expand the “Query” section.  Modify it to show just the discussions for your site.  Then click OK.  Verify that you can see your discussions.


2) This is where things get a little tricky.  You will need to access the ItemStyle.xsl file of your site, and modify it by adding a new template within the file.  Just find a spot where the templates are within that file and copy and paste the following template entry (be sure to keep what you already have in that file):

<xsl:template name="DiscussionAndReplies" match="Row[@Style='DiscussionAndReplies']" mode="itemstyle">
 <xsl:variable name="vv1"> 
 <xsl:value-of select="@LinkUrl"/> 
 <xsl:variable name="formattedLastUpdatedDate">
 <xsl:value-of select="ddwrt:FormatDateTime(string(@DiscussionLastUpdated) ,1033 ,'dd MMM yyyy')" />
 <xsl:variable name="listTitleEnd">
 <xsl:call-template name="substring-before-last">
 <xsl:with-param name="list" select="@LinkUrl" />
 <xsl:with-param name="delimiter" select="'/'" />
 <xsl:variable name="listTitle">
 <xsl:call-template name="substring-after-last">
 <xsl:with-param name="string" select="$listTitleEnd" />
 <xsl:with-param name="delimiter" select="'/'" />
 <xsl:variable name="DisplayTitle">
 <xsl:call-template name="OuterTemplate.GetTitle">
 <xsl:with-param name="Title" select="@Title"/>
 <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
 <xsl:variable name="LinkTarget">
 <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
 <div class="item link-item">
 <a href="{$vv1}" target="{$LinkTarget}" title="{@LinkToolTip}"> 
 [<xsl:value-of select="$listTitle" />] <xsl:value-of select="$DisplayTitle"/> - Replies:(<xsl:value-of select="substring-after(@ItemChildCount,'#') "/>) - Last updated: <xsl:value-of select="$formattedLastUpdatedDate" />

3) Once you’ve done that, go back and edit your Content Query Web Part.  Now, scroll down to “Presentation” and expand it.  Be sure to select the sorting / counts you’d like displayed.  Then be sure to select your new style template you just added.


5) If you are using SharePoint 2013, you will want to make sure you add the entry for the ItemChildCount, as it will not be picked up automatically.  (I spent a good couple hours trying to figure out why it would display in SP2010 and not SP2013.)


6) Click ok, and voila!  A nice rollup of a more detailed view of the discussion content on your site.


Modify “Upload To” (“Destination Library”) Choices For Discussions

I will start out with a caveat by saying that I have not tried this script on 2013.  However, the “Upload file” dialog also has an iframe like 2010, so I believe it should work, or will work with some minor alterations.

The problem we had is that users have permissions to contribute to multiple document libraries, however, for a specific discussion board, we wish to have them upload their attachments (when not using the “Attach File” option, but rather the “Upload file” option), to a specific document library.  The beauty of having the users create their posts using this method is that it allows the content to be directly embedded in the post itself, rather than having to click on the “View Properties” link to get to the attachment.


SharePoint however, does not present a way to modify the list of upload locations it presents.  Whilst browsing the interwebs, I did find ways that recommend modifying the underlying aspx pages, however, trying to adhere to what Microsoft recommends, I never modify these pages unless it has been recommended.


Undesired choice appears in “Upload Document” select box:


Find the value of the option we wish to remove:

Add the following script to your masterpage. This assumes you already have a reference to jQuery lying around. You may need to update the “live” reference to “on” if you have a new version.

//for removing the load detecting

var hideRibbonTimeout = 0;

var newButtonPresent = false;


//check to see if this the discussion board we want to trim

if (jQuery('#s4-titlerow a:contains(Product)').length > 0) {

       setTimeout(HideRibbonButton, 10);


//replace the current "Upload File" button to override the SharePoint button

function HideRibbonButton() {

       $('a[id*="UploadFile-Large"]').replaceWith('<a class="ms-cui-ctl-large newDialog" id="btnUpload" aria-describedby="Ribbon.EditingTools.CPInsert.Links.UploadFile_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.EditingTools.CPInsert.Links.UploadFile-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/1033/images/formatmap32x32.png" style="top:-224px; left: -64px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Upload<br>File</span></a>');

       if (jQuery('.newDialog').length> 0) {

              newButtonPresent = true;



       if (hideRibbonTimeout < 1000) {

              if (newButtonPresent == false{

                     setTimeout(HideRibbonButton, 10);




//handle the "Upload File" click and create our own upload

$('#btnUpload').live('click'function () {

       newButtonPresent = true;


              url: L_Menu_BaseUrl + "/_layouts/RteUploadDialog.aspx?LCID=1033&Dialog=UploadDocument&UseDivDialog=true",

              title: "Upload a file",

              dialogReturnValueCallback: function (result, value) {

                     if (result == SP.UI.DialogResult.OK) {

                           //adds the link to the body of the discussion post





       setTimeout(function () {         

       //finds the upload choice dialog box

              var dlg = SP.UI.ModalDialog.get_childDialog();

              if (dlg != null) {

                     var dlgWin = $("html"window.parent.document);

                     //get the iframe with the select box

                     var dlgCont = $(dlgWin).find("#dialogTitleSpan:contains('Upload a file')").parent().parent().parent().find('iframe');

                     //remove the option we want taken out

                     $(dlgCont).contents().find("#ctl00_PlaceHolderRteDialogBody_TargetList option[value='3141e042-d74f-440d-b836-a82b79a576f5']").hide();


       }, 1000);



Upload choice has been removed and users are now directed to upload to the correct document library.


SharePoint Designer and the Infernal Checkmark

Probably my biggest pet peeve with SharePoint Designer, other than the occasional lock up and crash, is that frequently it will show files as being checked out when they are actually not.  This is particularily annoying, because you will have to pull up the site in a browser and check it out from there to do any edits on the file.   I still have not figured out a good reason for this, other than that the “value” for this appears to come from the user cache, rather than from the server.  Kind of a poor implementation in my opinion.  Regardless, at least it is fairly easy to resolve.  Just browse to (from Windows 7):


Then find the site that is giving you grief and delete the associated files.  SharePoint Designer will rebuild them next time you pull up the site.

CAML Query By User

CAML can be rather hairy, and it took me some digging to find out how to query a list for items assigned to a user (of the “User” type).  It turns out the best method to do that is to query by the user profile id.  This will pull you back items for just that specific user.

<fieldref name=”PersonFieldName” LookupId=”TRUE”/>
<value type=”int”>UserID</value>

Set Up – Web Config Changes For Customization

Alright, first post, but a rather necessary one. Every time I do a new SharePoint installation, I find myself constantly going straight to the web.config file to make a couple changes.  If you have spent any time with SharePoint you already know about these, but I find it’s always good for a reference.

I know that it’s not recommended, but I find creating an entry in the PageParserPath block to be invaluable for testing out some code against the API in a quick and dirty fashion. It beats having to pack up and deploy features every time I want to test a line of code.

1. First create a folder in your “Pages” directory (once you’ve turned publishing on)

2. Then, to add runnable ASP pages with custom code, modify the PageParserPaths block of the web config:

<PageParserPath VirtualPath=”/pages/asp/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />

The other thing I do right out of the gates is to change the error reporting over, so that I start getting valuable info, instead of the canned SharePoint error screens, which are seldomly informative.

<SafeMode MaxControls=“200“ CallStack=“false“…


<SafeMode MaxControls=“200“ CallStack=“true“…


<customErrors mode=“On“/>


<customErrors mode=“Off“/>