Friday, 20 June 2014

Set the refinable property to true for Managed Metadata Property in Search Service Application and do full crawl using PowerShell

Hi Again,

I came up with a requirement where I want to show the custom managed metadata property in the search refinement web part in the search results page.

By default the refinable property of any managed property is non set as false/not active. In order to show a property in the search refinement web part , it has to be active/true.

Below is the PowerShell script I wrote to update the custom managed metadata refinable property and then I did the full crawl.


Hope this is helpful.
Cheers,
Isha Jain  

Wednesday, 28 May 2014

SharePoint 2013 Exception from HRESULT : 0x80131904


Hi All,

I am recently involved in big migration project from SharePoint 2010 to SharePoint 2013. During this journey I come across a very weird exception - Exception from HRESULT : 0x80131904.
One of the site collections in the migrated web application is giving me this issue for all the users except site collection administrator. When any user other than site collection administrator tries to either change master page or page layouts under look and feel section in the site settings page. The user is getting the below error.



I have checked the permissions for the below lists and it all inherits from parent.
  • Master Page Gallery
  • Device Channel
Then I thought is it something related to windows to claims conversion , as I am getting the below error when I ran Test-SPContentDatabase.

"The web application is configured with claims authentication mode however the content database you are trying to attach is intended to be used against a windows classic authentication mode."

then I ran the below script to convert users from Windows to Claims to my content database, but still no luck.

Windows to Claims Conversion:


I have also tried deleting the master page gallery and importing from other working site collection but still the same error message.

ULS logs also giving me very weird errors like below:

Invalid column name 'tp_IsCurrent' - from the SQL executed for AllUserData table of the content database. When I read more about this column in the database I found the below description.

tp_IsCurrent: When a file is checked out, tp_IsCurrent is set to false on that file’s record, and a new line is created for the checked-out version of the file (wherein tp_IsCurrent becomes true).

I have almost lost my patience as I have spent more than a week to troubleshoot this issue. Then I found a light in the tunnel. I tried moving one of the items "BlankWebPartPage.aspx" from the master page gallery to a blanknew document library and have found that it also copies the below fields and content type in the document library when I copied the file.



Content Type: Page Layout

When I click on any of the above lookup fields, I got access denied for all the users except site collection administrators. Then I realised , it is something to do with the access with the above lookup fields.

Then I found, the nice blog explaining about the cache Profiles
http://sureshpydi.blogspot.com.au/2013/10/cache-profiles-in-sharepoint.html

and I found my solution to the problem, it is the Cache Profile list has unique permissions. I then just deleted the unique permissions from my cache profile list and everything started working :).


Hope this could save some of your time.

Cheers,
Isha Jain

 

Thursday, 17 April 2014

How to call and pass parameter from one PowerShell script file to another?

I came across a scenario where I have to call another PowerShell script file and pass the current PowerShell script file input parameter to this second file.

PowerShell as the name says is very powerful and I was able to achieve my requirement with a simple expression called as "Invoke-Expression" in PowerShell.

Just to explain you how I have achieved my above requirement, I have created two demo PowerShell files called First.ps1 and Second.ps1. I am gonna show you how I have called First.ps1 and invoke the Second.ps1and pass the First.ps1 input parameter to the Second.ps1 with "Invoke-Expression".



Hope this is helpful.
Cheers!!
Isha Jain

Monday, 31 March 2014

Upgrade Search Settings and result sources using PowerShell in SharePoint 2013

I came up with a requirement where I want the user to search the results only from the site collection level. In SharePoint 2010, we all know there are search scopes which help us to narrow down our search based on content sources, web address and metadata. However; there is no search scopes in SharePoint 2013. There is a new concept similar to Search Scope called as Search Result Sources.

This Result sources can be created at "Application Level", "Site Collection Level" and "Site Level".

You could find more information on Result Sources in SharePoint 2013 @ http://technet.microsoft.com/en-us/library/dn186229(v=office.15).aspx

I decided to script out the following
1. Creation of Enterprise Search Centre site
2. Update the search settings to point to this new search centre instead of default OSSSearchResults page.
3. Create a site collection level result source
4. Update the search results webpart properties to query only at above created site collection result source.

1. Create Enterprise Search Centre via PowerShell

Note: you need to activate the "BaseSite" Collection hidden feature before creating the search centre.
2. Settings the results page for your above search centre

3. Create a Site Collection level result source

4. Update the search results webpart to use this above result source for query.

Hope you like my approach.
enjoy!!
Isha Jain

Runtime error when creating SharePoint 2013 Pulishing site

Today, I received a very strange error when creating a sub publishing site in SharePoint 2013. I received the below error runtime error with the famous yellow screen.



I am surprised to see this error and I have full control to the site and uls logs says access denied to one of the mobile channel list. I wondered what is mobile channel list is, then after much searching I have found that there is a new feature introduced in SharePoint 2013 called device channels.

With Device channel in SharePoint 2013, you can render a single publishing site in multiple ways by using different designs that target different devices like Mobile, i-Pad etc.

In order to resolve this error, you need to grant at least read only access to all the users to this device channel list or break the unique permissions to this list. Device channel list is hidden and can be accessible via site settings -> Device Channels




Thus to solve the above error while creating the sub publishing site, at least provide read only permission to sub site owners at device channel list.

Hope this must have saved lot of your time.

Cheers,
Isha Jain



 

Friday, 15 November 2013

Add Custom Web Parts to a page and Connect them using PowerShell


These days I am working heavily on SharePoint CSOM and BCS (Business Connectivity Services). I have created a sandbox package with multiple custom business data and html form data web parts.

The reason why I am writing this blog is to share with you some of the cool stuffs I did with PowerShell in the project.

I have written many automation scripts to create web part page, add web parts to this page and then connect to them on a single click using PowerShell.

First thing first…

1.       Create a web part page using PowerShell:



2.       Add web part to this page:



3.       Connect web parts in a page: In this script I have shown how we can connect

a.       Query String filter Web Part with Business Data List Web Part

b.      Query String filter Web Part with Business Data Item Web Part

c.       Business data List Web Part with Business Data Item Builder Web Part

 



Have Fun!

Isha Jain

Thursday, 25 April 2013

Paste content into SharePoint with no formatting

Hello Again,

These days I am working heavily into SharePoint Ribbon customization. If you have not read my previous blog on this, I would recommend you to read Previous Ribbon Blog before reading this one.

SharePoint 2010 brings the new evolution in user interface and have brought common functionalities into same page by introducing the Ribbon concept.

In SharePoint user is allowed to copy content from various sources like email, office applications like word, excel  and paste into SharePoint.

By default there are two ways to paste content into SharePoint from ribbon.


1. Paste (paste content with styles and formatting)
2. Paste palintext (paste content without styles but keeps the formatting)


However; pasting the content even as Plain text from word and other sources into SharePoint  introduces breaks and other markup issues in Html.

Paste  (format:break line and color:Blue)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

Paste Plaintext (only format:break line)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

I wanted to achive something shown below.

Paste with no formatting (no format no color)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null Write-Host "Hello All"



I have created a sandbox solution and added element.xml as shown below. On click of this flyout anchor menu I have called a javascript function as defined in commandaction attribute in the command handler.

Hope you find this useful.
Cheers,
Isha Jain

Friday, 5 April 2013

How to find a SharePoint field from GUID

Hello,

I have been in a scenario where I need to find one of the SPFields from its GUID. Its again PowerShell who saves my time.


$site = Get-SPSite -Identity "http://Site"
$web=$site.RootWeb
$field=$web.Fields[[Guid]"E9359D15-261B-48f6-A302-01419A68D4DE"]

That's it, I am done!!!

Cheers,
Isha Jain

Monday, 25 March 2013

Find all the sites where the feature is activated

Hi,

I have been struggling how to find out the lists of sites where my feature is deployed.

Below PowerShell command which helped me.



Instead of  using "Write-Host", I have used "Write-Output" which will give output in my output.txt file.

Note: Write-Host will write the output in the console while Write-Output helps to write the output in some file.

Hope this is useful.
Cheers,
Isha

Monday, 11 March 2013

Fetch Rss feeds into SharePoint List

I  had been into a scenario where I need to search the results from one of the Rss feeds into SharePoint search results page.

This means the data from this Rss feeds had to be into SharePoint content database and then SharePoint search crawler will crawl the content and made the content search able into the results page.

So I came up with a design of fetching the data from the Rss feeds into the SharePoint list in an hourly basis and will display the top 10 results into the home page and user can search on this Rss feeds.

In this design I need
1. Rss Feed link (http://feeds.bbci.co.uk/news/rss.xml)
2. SharePoint Custom list which will store the content from Rss feed.
3.Content Editor web part (CEWP) to display the top 10 results in to the home page.
4.Fetch the latest results into the SharePoint list in every one hour.

I am using SPServices to add/update the Rss Feeds into SharePoint list. In order to know more on SPServices and how to perform CRUD operations, Please visit my blog on CRUD operations using SPServices.

Step1: Fetch the Rss Feeds

At First, Created  a Custom List called RSS Feed with the custom columns Content, PublishedDate, FeedLink and Title.

So what I am doing here is, Calling Google feed api using  jQuery ajax to fetch the Rss feed by passing query parameters, q as Rss Feed url link and num to -1 to fetch all the results back into json object and then iterating each object and storing into SharePoint list.

Step2:Store the feeds into SharePoint List

Step3: Display the content from SharePoint List in the home page using CEWP.

Step4: Fetch the latest feed in every hour.

Hope you find this blog useful.

Cheers,
Isha Jain

Sunday, 10 March 2013

SharePoint Ribbon Customization

Ribbon is one of the new features introduced in SharePoint 2010. After office client, Microsoft introduced ribbon in the similar fashion in SharePoint.

Ribbon in SharePoint 2010 provides the common place for most of the controls that you will need, Ribbon  is divided into basic four sections as shown in Fig 1 below.






1. Tab
2. Group
3. Controls
4. Contexual Tab









The architecture of Ribbon allows you to customize by creating xml files.

Inorder to understand how SharePoint implements its Ribbon, there is a XML element file at
%Program Files %\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML

If you open this xml file, you will see that its a huge file. Don't get afraid with this huge file.
Lets understand how SharePoint implements the Ribbon functionality.

The main element in the "CMDUI.xml" file is the "CommandUI" element, this element holds all the controls and the templates for the Ribbon.

Ribbon element holds all the controls like Tabs, Group, Controls, Contextual Tab.

Templates element has GroupTemplate element. Each GroupTemplate element specifies the mode in which the controls within that group will be rendered.

As you can see in the ribbon image Fig 1, some of the controls are rendered as large icons whereas  others like "Page History", "Delete Page" etc. (under Manage group) are rendered in medium size icons. All of these are controlled by GroupTemplate element.


Now, Lets have a close look at Ribbon element. Ribbon element has two child elements "Tabs" and "ContexualTabs". Each of these element further has Groups and Controls element which hold the html contols like label, textbox , combobox, dropdown. etc.

I hope you have got the clear understanding of the CMDUI.xml file.

Now lets try to customize the ribbon. In this example I am going to add the caption to the table when a user inserts the table into the page. 

When a user edits the page and inserts the table into the page, "Table Tools" contextual tab shown below is displayed. What I am trying to achieve using this custom control is, when user enters some text into this highlighted textbox and hits save,  I am adding the Caption child element to the table. This is achieved by specifying the custom .js code into the command handler element.


Adding any custom controls into the ribbon can be achieved by creating custom action element.xml file in SharePoint 2010.

The CustomAction element has two main elements: CommandUIDefinitions and CommandUIHandlers.

CommandUIDefinitions hold all the custom controls definitions and the CommansUIHandlers hold the actions against each controls.

There are few things to keep in mind.
CustomAction Location="CommandUI.Ribbon" -  tells SharePoint that you are adding controls into the Ribbon.

CommandUIDefination Location="Ribbon.Table.Layout.Summary.Controls._children" - tells SharePoint that the controls need to be added into the "Ribbon.Table" contextual tab under "Layout" tab under "Properties" group.

Command attribute of the control is the place you specify what action you need when a user clicks on the control. Action is specified in the CommandUIHandler element. In my example I am adding the caption element to the table.

QueryCommand attribute of the control is fired when the page is rendered. Action is specified in the CommandUIHandler element. In my example I am fetching the caption element of the table and storing into the textbox.

There are few .js files for Ribbon which are present at 14 Hive layouts folder. These files hold the actions (CommandUIHandler) part of the ribbon.

For Rich Text Editor : "SP.UI.RTE.js"
For Publishing Site Rich Text Editor:  "SP.UI.RTE.Publishing.js"


Hope you find this blog useful.

Cheers,
Isha Jain





Saturday, 23 February 2013

CRUD operations using SPServices

Hello,

These days I am working on client side scripting in SharePoint 2010. I have heavily used SPServices.

SPServices is a JQuery library which interacts with SharePoint web services. It is a script based technology which allows us to talk to SharePoint through its web services.

The syntax is pretty simple, similar like JQuery and other scripting libraries. I have shown below the sample examples to achieve the CRUD operations using SPServices.

Get All the items from the list based on the condition using GetListItems

function ProcessData(xData)
{
  $("#content").html('');
  var ulTag=$('<ul style="list-style:square;"></ul>');  
  $(xData.responseXML).SPFilterNode("z:row").each(function() 
  {  
    var liTag=$("<li></li>").append($(this).attr("ows_Title"))
    ulTag.append(liTag);
  });
  $("#content").append(ulTag);    
}

$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Expires' /></IsNotNull></Where></Query>",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Expires' /><FieldRef Name='Body' /></ViewFields>",
    completefunc: ProcessData
    });   
    
});   

Delete All the items from the list using SPUpdateMultipleListItems

function DeleteAllItemsFromList()
  {
    $.SPServices.SPUpdateMultipleListItems({
    listName: "Announcements",
    CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",
    batchCmd: "Delete"});
  }

Add item to a list using UpdateListItems

function AddItemsToList(title,content)
  { 
   $.SPServices({
   operation: 'UpdateListItems',
   listName: "Announcements",
   updates: '<Batch OnError="Continue">' + 
             '<Method ID="1" Cmd="New">' +
             '<Field Name="Title">'+ title +'</Field>' +
             '<Field Name="Body">'+ content +'</Field>' +
    '</Method>' +
             '</Batch>',
   completefunc: function(xData, Status)
        {}});  
  }

Update item in a list using UpdateListitems

$function UpdateListItem(itemID)
  { 
    $().SPServices({
    operation: 'UpdateListItems',
    async: false,
    listName: "Announcements", 
    updates: '<Batch OnError="Continue">' + 
             '<Method ID="1" Cmd="Update">' +
      '<Field Name="ID">' + itemID + '</Field>' + //Specifying the item id is very important here
             '<Field Name="Body">'+content+'</Field>' +
      '</Method>' +
             '</Batch>',
    completefunc: function(xData, Status)
    {}
   });  
 }
 
 

 




Cheers,
Isha Jain



Friday, 4 January 2013

PowerShell Basic - Speical Character

Its very difficult to remember every syntax and what it refers to when you are working with myriad of languages.

Below are the useful basic Characters which you need when you work in Power Shell.

1. Single Line comment representation : #

Ex. # This is a single line comment 


2. Multiple Line comments representation: <# #>

Ex. <# This is a Multiple

           Line Comments #>

 

3.Declare a variable: $

Ex. $a=$null

 

4.Item inside for each loop or current pipeline object : $_

Ex. .... | Foreach {Write-Host $_}

 

5.Continue command on next line: `

Ex. Write-Host `

      "Hello World!!"

 

6.Where-Object shortcut : ?

Ex. .... |  1..5 | ? {Write-Host $_ % 2} # Here % represent mod

 

7.Not Shortcut : !

Ex.  $a=$null | if($a) {Write-Host "$a is not null"}

 

8.For each Shortcut: %

Ex. .... | % {Write-Host $_}

 

9. To catch the output of the command and pass it to the another command: |

Ex.  get-process | select-object -first 3


10. Declare Array: @()

Ex. $a= @("one" , "two" , "three")


11. Declare Hash table: @{}

Ex. $a= @{"1" = "one" ; "2" ="two" ; "3" ="three"} 


12. To specify a range: ..

Ex. 1..5 | 


Hope this help

Isha


 

 


Monday, 1 October 2012

Internal server error in SharePoint search

When running SharePoint search  I stuck with the error saying nothing but Internal Server error.
After much hit and try I found that below steps helped me in solving the error.


  • Restart the SharePoint timer services/ IIS/ SharePoint Search service / Restart Server
  • Enable "Search Server WebParts" feature on the Site Collection level.
  • Run the "Search and Process" Timer Job
  • Make sure your search service application is associated with right proxy! (Go to Application Management >> Select Configure service application associations under the Service Application heading >>Select the default Application, select Your sevice app, Then click on set as default)
  • ensure that the "SharePoint Server Search" and "Search Query and Site Settings Service" services are running
  • Verify your AAM Settings
  • ensuring that the application pool is assigned correctly
  • Remove and reinstall the search application


 

Monday, 17 September 2012

NetBiosDomainNamesEnabled and SharePoint User Profile Service Application

NetBiosDomainNamesEnabled  property is set for every UPA (User Profile Service Application). By default this property is set false. We need to enable NetBios Domain Names for UPA when Domain Fully Qualified Domain Name (FQDN/DNS) is different then NetBIOS name.

Now the question araises how do we check whether the DNS and NetBIOS names.

Open Active Directory Users and Computers, right click and choose Properties.
you will see the below properties.

1 is your DNS/FQDN and 2 is your NetBios Domain Name.


If you dont have access to your domain Active Directory you can get the information using PowerShell command.

To find FQDN

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
To find NetBIOS name
Get-ADDomain -Identity "YourFQDN"
Now if you find that DNSRoot and NetBIOSName properties are not same then before synchronizing your UPA enable the NetBiosDomainNamesEnabled.
Below is the PowerShell command to enable the import of NetBios Domain Names.
Get-SPServiceApplication 
(lists the Service Applications and their GUIDs)
$UPA = Get-SPServiceApplication –Id <GUID of User Profile Service Application>
$UPA.NetBIOSDomainNamesEnabled=1
$UPA.Update()

Then start the UPA synchronizartion.

Hope this help!!
Cheers!!
Isha Jain




Friday, 14 September 2012

User Profile Synchonization Service Stuck on Starting

Starting User Profile Synchonization Service in SharePoint is always a big pain. Most of the time it stuck on Starting mode and you dont have controll to stop this.

You can stop the User profile Synchronization Service.
http://donalconlon.wordpress.com/2010/08/27/deleting-the-search-service-application/

There are many reasons for this.

1. The account which you are using to run the service might not have "Replicate Directory Changes" permission in your AD.

Solution:
http://www.codeproject.com/Articles/358855/user-profile-synchronization-service-not-starting

2. This account which you are using to run the service  might not have explicit access to the folder C:\Program Files\Microsoft Office Servers\14.0.

The reason we need to give explicit access to the folder is User Profile Synchronization service access AD through ForeFront Identity Manager Synchronization Service.

Thus in order to start User Profile Synchronization Service, Microsoft Forefront Identity Manager Synchronization Service have full access and this Forefront Synchronization service sits at C:\Program Files\Microsoft Office Servers\14.0.\Synchronization Service\UIShell called as miisclient (Microsoft ForeFront Identity Manager).

Solution: Give access
http://melick-rajee.blogspot.com.au/2011/07/user-profile-synchronization-service.html

3.The password for the account which you are using to run the service is not correct.

Solution: Enter proper password or if the password is expired reset the password in AD and then  following the below link
http://info.izzy.org/Blog/archive/2010/08/04/how-to-fix-an-out-of-sync-password-issue-in-sharepoint-2010.aspx
http://blogs.technet.com/b/seanearp/archive/2011/01/25/updating-passwords-on-sharepoint-2010.aspx

Hope this help.
Cheers
Isha
 

Thursday, 13 September 2012

Fix for SharePoint Search 2010 not able to connect to machine that hosts the admin component.

I faced a ugly error today on my central admin says Search Service not able to connect to the machine that host the administration component.

I read many blogs and mostly said create a new Search Service Application. I tried that but still the problem exists.

Below are the steps I followed to solve the issue of Serch Service Application.

1. Deleted the existing Search Service Application.
  
a. Get-SPServiceApplication
This will help to get the Search Service Application GUID.Copy the Search Service Application GUID
b. stsadm -o deleteconfigurationobject -id <GUID> from step a.

2. Delete the Application Pool for Search Service Application

a. Get-SPServiceApplicationPool
This will lists all the Service Application Pool. Find the one associated with Search Service Application
b.Remove-SPServiceApplicationPool <ApplicationPoolName>

3.Delete the CrawlStoreDB, PopertyStoreDB and AdminDB from the SQL Server responsible for holding all information related to Search Service Application.

Above three steps are just the clean up steps

4.Now Create the Search Service Application using the below blog
http://waelmohamed.wordpress.com/2011/05/31/configure-sharepoint-2010-search-service-application/

5.Now If you still see the error then the trick is beloe simple STSADM command
Resolution: Run the following stsadm command

stsadm -o provisionservice -action start -servicename osearch14 -servicetype "Microsoft.Office.Server.Search.Administration.SearchService, Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

do a simple iisreset /noforce

Thats it!!! it will start working!!!

Hope this will help and fix the issue.
 

Tuesday, 11 September 2012

How to split one file into many based on condition using PowerShell


I have been in a scenario where I have to spilt the CSV file content into many .CSVs based on some condition.
Below are the steps I have followed to achieve this using PowerShell.

At First I import the CSV file which I need to spit and then for each data row in the csv file call the function “CreateOrAppendCSV “  by passing two parameters each data row entry and filename.

IMPORT-CSV “C:\Source.csv” | Foreach-Object { $path=$filePath+".csv"; select-object -input $_ -prop @{Name='Name';expression={$_.Name;}},@{Name='Url';expression={$_.Url;}} |  CreateOrAppendCSV  $_ $path }

# This will create the new csv file if not exists or append to the existing csv file for position
Function CreateOrAppendCSV{
Param($item,$path)
If(Test-Path $path -PathType Leaf) # This Test-Path command checks for file exists or not
{
    # If file exists then append using ADD-Content Command  
   $fileImport= Import-Csv $path
   $newItem= New-Object PsObject     
   $newItem | Add-Member -MemberType NoteProperty -Name "Name" -Value $item.Name
   $newItem | Add-Member -MemberType NoteProperty -Name "Url" -Value $item.Url
   $newItem | ConvertTo-Csv  -NoTypeInformation|select -Skip 1 | Add-Content $path
}
Else
{
   $item | Export-Csv -Path $path -NoTypeInformation #Export if file not exists.
}
}

Hope this help.
Isha Jain

Friday, 7 September 2012

PowerShell with Exchange

Here is something new I learnt today.

In order to create a mailbox for an active directory user using powershell we need to Get-PSSnapin for Exchange and Import-Module for Active Directory.

Clear-Host

#SnapIn for Exchange Mailbox
if(-not(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"}))
{
  Add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
}

#SanpIn For SharePoint
if(-not(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.SharePoint.PowerShell"})) {
  Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

# Add Active Directory Snap-In
Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory

Once this Import is done we can call the "New-Mailbox" command which will create the mailbox and AD user.

This command will create mailbox along with user creation in AD.

New-Mailbox -Name $displayName -Database $dbName  -Password $password -UserPrincipalName $userPrincipalName -Alias $samAccountName  -DisplayName $displayName -FirstName $givenName -LastName $surname -OrganizationalUnit $ouPath    

This command will create user in AD and then you can enable the mailbox

New-ADUser -Enable $True -PasswordNeverExpires $enable -PassThru  -Name $displayName -GivenName $givenName -Surname $surname -DisplayName $displayName -EmailAddress $emailAddress -SamAccountName $samAccountName -Title $title -Department $department  -UserPrincipalName $userPrincipalName -Path $path -AccountPassword $password

Enable-Mailbox $userPrincipalName –Database $dbName

Hope this help.
Isha
 

Thursday, 30 August 2012

Export SharePoint List data into CSV file

Hi,

I have found couple of blogs explaning the reverse way of expoting csv file data into SharePoint list. I have accomplished the other way around and hence thought of sharing this with you.

InOrder to export data from SharePoint list into CSV file, lets first query SharePoint list and get the required items and then we will export these items into CSV file.


$spSiteUrl = "http://sharepointwebapplication"
$listtitle="My Custom List"
$spWeb= Get-SPWeb -Identity $spSiteUrl
Function ImportDataFromListToCSV
{
  IF($spWeb -ne $null)
  {
  $list = $spWeb.Lists.TryGetList($listtitle)
  $exportlist = @()
  $items = $list.Items
  Write-Host "Exporting........" -ForegroundColor Yellow
  if($items -ne $null)
  {
    #Here "givenName" column name for CSV file and "Given Name" column name SharePoint List
    $items | %{ select-object -input $_ -prop @{Name='givenName';expression={$_["Given     Name"];}},@{Name='surname';expression={$_["Family Name"];}};}| Export-Csv -Path C:\Demo.csv -NoTypeInformation
    Write-Host "SharePoint list data is exported successfully." -ForegroundColor Green
    $spWeb.Dispose()
 }
 Else
 {Write-Host "No data found in the list "$listtitle -ForegroundColor Yellow}}
}

Enjoy PowerShell,
Isha Jain