Sunday, September 28, 2014

Format Commands for PowerShell Output .

I was trying to get the list of timer jobs and their frequency in a table format using powershell. I searched technet and after reading through this  I figured it out.

I tried Get-SPTimerJob |Format-Table -Wrap   -AutoSize -property name,schedul
e,description,webapplication > D:\Timerjobs.txt.

Somehow the output text file showed only the name of the timerjobs with the following message

"WARNING: 3 columns do not fit into the display and were removed."

After a subtle thought I used the following command and got the results in a way I wanted.

Get-SPTimerJob |Format-Table -Wrap  -property name,schedul
e,description,webapplication > D:\Timerjobs.txt

Another interesting parameter you might want to use is ConvertTo-HTML , which will create a HTML report .

Get-SPTimerJob |ConvertTo-HTML -property name,schedul
e,description,webapplication > D:\Timerjobs.htm

Hope this helps you.

Saturday, September 20, 2014

The term 'get-spfarm' is not recognized

I was using Windows Poweshell - ISE for creating some power shell scripts and got the following error.

"get-spfarm : The term 'get-spfarm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

Checked the PowerShell Code and found that I forgot to add powershell snapin and added the following and the script got executed.

Add-PSSnapin "Microsoft.SharePoint.PowerShell" 

Thursday, September 18, 2014

ExecuteOrDelayUntilScriptLoaded with SP.JS

There was a survey that the management wanted to publish depending on the domain of the logged on user. Say if the user belongs to Asia and America, the system should popup a dialog for the survey. We decided to use JavaScript client object model to find the domain of the logged on user.

We used the following code on the home page which already had some JavaScript menus.

ExecuteOrDelayUntilScriptLoaded(init, "sp.js");

function init() 
{
            this.clientContext = new SP.ClientContext.get_current();
            this.oWeb = clientContext.get_web();
            currentUser = this.oWeb.get_currentUser();
            this.clientContext.load(currentUser);
            this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    
}

After applying this code the JavaScript menus were not coming up. So checked the code and found that ExecuteOrDelayUntilScriptLoaded has to be used with a function name. Hence changed the code like below and JavaScript menus started coming up.

jQuery(document).ready(function() {
 ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
});
       
  //      ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
         function init() {
            this.clientContext = new SP.ClientContext.get_current();
            this.oWeb = clientContext.get_web();
            currentUser = this.oWeb.get_currentUser();
            this.clientContext.load(currentUser);
            this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
   
        }

Hope this helps you!!!



Tuesday, September 16, 2014

Merge ULS Logs to find Correlation ID

There was an issues in the BCS settings of my SharePoint 2010 farm and I need to search for a particular message in my farm. I had to login each searver of my farm search through the ULSLogs to find a specific error message.

I did want to find a shortest route for this and found the Merge-SPLogFile Power Shell that will merge all the logs from your farm to a specific directory depending on the parameters.

This will take some time to execute, and at the end you will have the ULS Logs at  one place , which can be used to skim through the errors.

Hope this helps you.



Monday, September 15, 2014

Cannot start service SPAdminv4 on computer . PSConfig fails "InvalidOperation Exception" after SP2 Install

I was setting up a new SharePoint server and after installing SP2, ran the PSConfig wizard which failed with the error "System.InvalidOperationException, “Cannot start service SPAdminv4 on computer ‘.'”.

Found this blog and followed the steps given. It solved the problem for me. Hope it helps you as well.

Powershell to find Orphaned Databases

To get a list of orphaned databases : Get-SPDatabase | where {$_.exists -eq $false}

To delete the orphaned databases : Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}

Hope this helps you

Sunday, September 14, 2014

Exception from HRESULT: 0x80131904 -While updating a list item.

We had this issue, in one of our application in my farm. User's were not able to edit a list and it was throwing this error. "System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80131904".

Googling pointed  out that there might be a problem in the content database.

1) So we increased the Content DB Autogrowth size from 50MB to 500MB. This has not resolved the issue.

2) Dropped the indexes and recreated the indexes for the problematic list. This also did not resolve the issue.

Finally found the issue is with UserType look-up fields did not have target list defined and hence cannot locate the users it needs to. So had to update the affected fields to the correct reference of User Information List, exported the list, deleted the original list item from the list settings (Make sure you have content DB backup) and import the list again. This solved the problem.

Many people had different way of fixing the "HRESULT: 0x80131904" error , but in my case it was for look up column. Hope it helps.