How to wrap long names in PowerShell text output

Sort of a self note here.
Quite often we are asked to display all sites or all webs. I get frustrated to see the urls, which are often long truncated with ellipses at the end. The following formatting will help:

$myWebApplication | Get-SPSite -Limit All | ft -Wrap
$myWebApplication | Get-SPSite -Limit All | Format-Table -AutoSize

Where $myWebApplication is just a variable where I read the webapplication where I am trying to find the site collections.


Add web part to Edit Form of a list

I came to know that I can add content editor web part in SharePoint page and add javascript code to it. For a specific purpose, I needed to add a web part in a list’s Edit form.
I made sure that I set up Launch from Dialog to No as shown below:
And then opened the Edit form in IE 11 and tried to do Settings > Edit Page as shown below:
But nothing happened.
Then I tried the same thing in Chrome and it worked just fine.

Sorry, there was a problem and we can’t open this document



I was testing migration of a SP 2010 site which used OWA to a SP 2013 environment. All was going well until I tried to open a word document and I saw this dreaded error:
So fire up the search engines wearing your trouble shooting hat. And you will get tons and tons of posts in similar line.
Finally, I saw this post:
Sorry, there was a problem and we can’t open this document
This has a lot of suggestions. But after spending hours and hours, one line caught my attention:
“Does the url work from the WAC server”
Now I am not sure what “the url” refers to. But I presumed that must be the url of the restored site collection. In my case I did not have a DNS entry and was using a temporary entry in my host file. I made sure I enter the same entry in the OWA server and do a ipconfig /flushdns.
And bingo! The above error was gone!

Patching language packs and patching to August 2015 CU



I was tasked with patching our DEVELOPMENT environment from SharePoint 2013 SP1 to August 2015 CU. I thought – huh – that is easy! Boy was I in for a big surprise?
When I downloaded the August 2015 CU and started installing, I got an error whose screen shot I don’t have. But the error indicated that the language packs are not updated. First update the language pack and then it will let you update to the CU.
We have language packs installed in the same environment. But what version of language pack do we have? In the Patch Status page if Central Admin, you will see some version numbers for the language packs. But what do these version numbers  mean? We have great blogs posts for determining SharePoint version numbers. But I could not come up with any clue what version numbers to the right of the language packs mean. So I had to take chances. I assumed that we do not have language packs upgraded to SP1. So let me download the SP1 language packs and try to install them. Worst case, it will say we have nothing to install.
So where can I download the SP1 version of language packs? You should get started from here:
Once in this page, select the language packs one by one and download locally. If you have 5 language packs already deployed, you have to download the SP1 version of these language packs 5 times.
Once you are done downloading, copy to SharePoint servers and install one by one and run SP Product Configuration Wizard in all non database SharePoint servers.
Once the language packs are installed, it is time to download the August 2015 CU. When you try to install the binaries, the installation will fail.
From here, you will realize that this is a known issue and it needs to be installed 3 times:
After the usual drill of running the Product Configuration Wizard, you have upgraded to August 2015 CU.
The next natural question is: are there language pack upgrades for August 2015 CU. For this I downloaded August 2015 CU for another language. I binary compared this with the English CU. I did not find any difference in them. Seeing this, I was pretty positive that there is no separate language pack for August 2015 CU.
The patch status page in our farm looks like the following now:

How to checkin all checked out files via powershell? – With a twist



One day, I got a request from a colleague to bulk check in files he has checked out. He also pointed me to this great post:

Thanks to Aanchal for this helpful post above.

However, as I often write, I work in a hurry in-between interruptions. Between phone calls and bosses stopping by. My colleague had the files scattered all over many folders and subfolders. Please note the following line:

$getFolder = $spWeb.GetFolder(“Shared Documents”)

If I run the above, I will barely touch the surface. Because all the files are distributed in unpredictable folders. On top of that, these were first time checkins. So
$_.CheckOutStatus -ne “None” does not quite catch these files. I however found that if you get the list and look for CheckedOutFiles, these files are captured. And then I used TakeOverCheckOut() for checking these files to me.
Here is the script, that worked for me:

Add-PSSnapin Microsoft.SharePoint.PowerShell

function CheckInDocument([string]$url, [string]$libName)

$spWeb = Get-SPWeb $url
$getLib = $spWeb.Lists.TryGetList($libName)

$getLib.CheckedOutFiles | ?{ $_.CheckedOutBy.UserLogin.ToLower() -match “Admin’s Network Id”.ToLower()} | %{

$myCheckedOutFile = $_

$myExactFolderName = $myCheckedOutFile.DirName.SubString(13) //This is //to get the exact folder path without the /sites/sitename, this number may //be different for you

$getFolder = $spWeb.GetFolder($myExactFolderName)

$getFolder.Files | Where { $_.CheckOutStatus -ne “None” } | ForEach {
Write-Host “$($_.Name) is Checked out To: $($_.CheckedOutBy)”
$_.CheckIn(“Checked In By Administrator”)
Write-Host “$($_.Name) Checked In” -ForeGroundColor Green


function CheckOuttoAdmin([string]$url, [string]$libName)
$spWeb = Get-SPWeb $url
$getLib = $spWeb.Lists.TryGetList($libName)

$getLib.CheckedOutFiles | ?{ $_.CheckedOutBy.UserLogin.ToLower() -match “mycolleague’sNetworkid”.ToLower()} | %{
Write-Host “Taking over Checkout $($_.LeafName)”
$myFile = $_



CheckOuttoAdmin “Your Site Collection URL” “Shared Documents”

CheckInDocument “Your Site Collection URL” “Shared Documents”

SharePoint file locked/ Checked out when it is not



Last afternoon, my boss came over and told a very important user is reporting he cannot check out a file from SharePoint as it is locked by another user.

So I noted the file’s location and told him I will start looking. And I banged my head and scolded me for not saving note from the last time when I resolved this. This is the deadly error when the file is not really checked out, but it is locked. Oops. What to do?

After googling the Bing a lot, these are the useful sites that came up:

But in our case the problem was we did not have access to the user. He was under the weather and gone. So I had to do it without the user.

This wait for 10 minute did not work for us at all.

I am an admin and I have access to servers and PowerShell. This Back in the Hack post is the key to resolving this problem. Thanks to gavinmckay:

The thing is I was in a hurry. Also this was in production and I did not have time to test and run this entire script. So I had to get this done via few commandlets.
Note that in this post there is a line which holds the key of the resolution. The line is

When I tried the above line, it bombed. That is because this was being tried with the admin context. It’s very important that you open the site as the context of the user to whom the file seems to be locked. Check out this line:

$impSite= New-Object Microsoft.SharePoint.SPSite($web.Url, $user.UserToken)

Here are the commandlets that were enough for me to do the release of the lock:

— Get the user

$myWeb = Get-SPWeb http://yoursiteurl (no pages/default.aspx)

$myFile = $myWeb.GetFile(“Shared Documents/****/****/your file name.xlsx”)

$myUserID = $myFile.LockedByUser.ID

$myUser = $myWeb.AllUsers.GetByID($myUserID)

— The following is the all-important piece, open the site as the user who locked the file and then release the lock

$impSite= New-Object Microsoft.SharePoint.SPSite($myWeb.Url, $myUser.UserToken);

$impWeb = $impSite.OpenWeb()

$fileURL = “Shared Documents/****/****/your file name.xlsx”

$impFile = $impweb.GetFile($fileURL)


Unable to open Office documents from SharePoint 2013



Some of us know about this:
Cannot open or create word documents in SharePoint 2013 with Office 2010 and Project 2013
In general when we get an error like below in the browser link:
then we tend to think that Office 2010 is mixed up with some Office 2013 components. So far, I never saw exceptions to this above rule. About a week back, I got a call from one user. And I confidently told him I know what is going on. And believe it or not, I could not find any trace of 2010 being mixed with 2013. And I gulped.
However, when I compared the version of Office 2013 365 Pro Plus between his machine and mine, I found his version does not match mine. So I requested our help-desk to repair his Office 2013 version and make it the same as mine. This resolved the problem.
Here is my laptop’s office version:

How to setup a development environment for office 365/ SharePoint online



I am a SharePoint Admin who dreams about migrating back to the development world. I attended this SharePoint/ Office 365 conference where I heard about the fact that I can setup an office 365 development environment practically free (about $8 a month) from the office dev environment. I am very bad at building virtual machines or laptops at home and always struggle with available time. So this is music to my ear. I thought I will give it a try on a Sunday afternoon after I was done with my exercise and other chores.
So where to begin? Let us begin at the office 365 developer site. The site is @
BTW, if you google the bing for Office 365 Developer Site, you will not find it. Easily at least. A very tempting link for Getting Started is right there. But let us not go there. Rather, on the left navigation, scroll down to DEV Program. Let us get started here.
You will see a Free Dev Program Sign Up link. I like free stuff. Let us sign up there and get our Office 365 subscription going.
So now, we have our new shiny office 365 developer subscription. After signing up, you will get an email. A screen shot suggests that this is indeed for one year:
My site is @
Guess what? I do not see SharePoint in my products in this screen:
But I registered for learning development on SharePoint online. Undeterred, I click on the admin tile. On the left nav, under the Admin section, I see a link for SharePoint. On clicking that, I see the SharePoint online admin screen. So I may not be too crazy after all. I have a few SharePoint site already pre-provisioned for me. Then it dawned on me that I am here to learn SharePoint online development. So I go back to this link:
Here you will see a section for Ready to Jump Right In. Well I created the accounts, so I thought I am just about ready. And I clicked. I am a SharePoint guy. So when I saw: SharePoint Add-Ins (formerly known as Apps for SharePoint), it caught my attention. So I clicked on the Get Started link. This brought me to the default page:
that says : Get started creating SharePoint-hosted apps for SharePoint. So I see this section for: Set up your dev environment and I get excited. I thought Office 365 development subscription will give me some kind of on-line development environment. And then I see this line:
•If you don’t already have Visual Studio 2013 or later installed, install it using the instructions at Install Visual Studio. We recommend using the latest version from the Microsoft Download Center.
Wait, where shall I install it? On my office machine with Windows 7 on hardly any RAM? What if my office does not like me any more? I will sit @ home and Starbucks taking interviews and doing what else? So I remembered about this article:
Now this is an article from 2013. After two years have passed, you will find a few changes and you have to find your way through the forest of unknown roadblocks. But let us give it a try. On your Office Portal Admin page:
you will see a link on the left navigation called Azure AD. I clicked on that. This will take you to:
And then will make you create a separate Azure account. Somewhere on this screen it will tell you that you have certain $$ amount of free Azure credit. I already told that I like free stuff. So I created my account. However, here you have to provide your credit card. And remember, I heard somewhere that I can get Office 365 developer subscription for about $8 a month. I don’t mind that for learning some cool development skills. But I told myself one thing, if I provision and logon to an Azure VM, I gotto remember to turn that off as soon as I am done. You will eventually see a screen like:
Select Virtual Machine and +New sign towards the bottom. Select From Gallery and select a Visual Studio track that you like. Once selected, it will provide you a machine/ dns name. Keep good note of that because you will need that information while rdp-ing onto the machine. Once the machine is provisioned, you will create a user and credentials. You will use this user for rdping into the vm. For me the dns name was:
Once the machine is provisioned and started, you will click the connect button below. I could not run or save the rdp file in IE11. So I tried Chrome to download the rdp file onto my laptop. While prompted for userid/ credentials, I am providing:\myusername
and credentials.
Next onto my dev learning journey.