Friday, 20 November 2015

Import Users from Excel to SharePoint using PowerShell

Import Users from Excel to SharePoint using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$userList=IMPORT-CSV C:\UserToUpload.csv -header("GroupName","UserName")

#Get the site name to the variable
$web = Get-SPWeb SiteURLHere

foreach ($user in $userList)
{
$groupName = $web.SiteGroups[$userList.group]
$user = $web.Site.RootWeb.EnsureUser($userList.user)
$groupName.AddUser($user)
}
Write-Host -ForegroundColor green "Users Added Successfully"
}
$Web.Dispose()

Import Excel to SharePoint Gruop List using PowerShell

Import Excel to SharePoint List using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$contents = Import-CSV ‘C:\Input.csv' -header("Employee ID", "Employee Name")
# Web URL
$webURL = “SITEURL here”
$web = Get-SPWeb -Identity $webURL
$listName = "ListNameHere"
$list= $web.Lists["$listName"] 
# Iterate for each list column
foreach ($row in $contents )
{
    $item = $list.Items.Add();
    $item["Employee ID"] = $row.GroupName
    $item["Employee Name"] = $row.Permissions
    $item.Update()
}
Write-Host -ForegroundColor green "List Updated Successfully"
$web.Dispose()

Export SharePoint Group to Excel using PowerShell

Export SharePoint Group to Excel using PowerShell

$siteUrl="SiteURLHere"
$groupName="GroupNametoExport"
$Output = @("GroupName|Name|Login|Email|Department|Title")
$web = Get-SPWeb $siteUrl
$site = $web.Site
$rootWeb = $site.RootWeb
$UserList = $rootWeb.Lists["User Information List"]
$web.SiteGroups[$groupName].Users|%{$user = $UserList.GetItemById($_.ID)
if($user -ne $null)
{
$JobTitle = $user["JobTitle"]
$Department = $user["Department"]
}
$Output += ($groupName+"|"+$_.Name+"|"+$_.UserLogin+"|"+$_.Email+"|"+$ Department +"|"+$JobTitle)
}
$rootWeb.Dispose()
$web.Dispose()
$site.Dispose()
$Output > "D:\MembersExport.csv"

Power shell

http://www.sharepointdiary.com/2013/07/export-sharepoint-users-and-groups-to-excel-using-powershell.html

Tuesday, 17 November 2015

RENAMING A SHAREPOINT 2010/2013 SERVER

RENAMING A SHAREPOINT 2010/2013 SERVER

Have you ever found yourself in the situation where you wished you had named your SharePoint server differently? Renaming that server isn’t exactly straight forward. You can’t simply rename the machine and call it good. SharePoint contains many references to the name of your machine throughout it’s database, and all of these must be changed as well. Luckily, Microsoft has provided us with a handy PowerShell cmdlet called Rename-SPServer to make most of these changes. There’s more to it than just this command, however, so I’m going to go through all of the steps that I have a lot of success with. In a nutshell, we’re going to first rename the server in SharePoint’s eyes using PowerShell, then actually rename the machine itself, fix a few things neither of those two steps updated for us, and run an upgrade command. And we should be doing all of this as the Farm Account to ensure we don’t run into any permission issues performing these steps.

If this is a 2013 server, we’re also going to have to contend with the Distributed Cache service. The first time I tried to rename a 2013 server I had a bear of a time with this service still having references to the old server name and not working properly. There is a specific order these steps have to go in, otherwise you can end up with trouble.
In detail, here are the steps that I take:

1. Log into the server as the Farm Account.

2. Open SharePoint Management Shell (PowerShell).

3. If this is SharePoint 2013, execute the command:

Remove-SPDistributedCacheServiceInstance
We need to remove this before the server is renamed. Doing this out of order I was running into many difficulties getting this service working again, and getting it to forget the old name of the server.

4. Next, execute the command:
Rename-SPServer -Identity “[old_server_name_here]” -Name “[new_server_name_here]“
You will probably see an “Object not set to an instance of an object” error message, this is normal, the farm was renamed.

5. Now rename the actual Windows server itself to the same name you gave the Rename-SPServer command. These must match, otherwise you’re going to end up with SharePoint Management Shell windows that say nothing but “Farm not found”.

6. Reboot the server.

7. Log back in as the Farm Account and open the SharePoint Management Shell(PowerShell) back up again.

8. Execute the command:

New-SPAlternateURL -WebApplication http://[old_server_name]:[central_admin_port]
-Url http://[new_server_name]:[central_admin_port] -Zone Default
The Rename-SPServer cmdlet doesn’t rename the alternate access mapping for Central admin for you… it doesn’t touch any of the alternate access mappings. You’ll need to repeat this command for every Web Application you may have that is simply the old servers name on different ports.

9. Now open up a regular ole’ command prompt and execute the following:
psconfig.exe -cmd upgrade -inplace b2b -wait -force
This will take a while. You also may get an error saying the User Profile Synchronization service failed to start, which is fine. You’ll need to go start that manually via Central Admin afterwards.

10. If this is a SharePoint 2013 server, let’s head back to SharePoint Management Shell and resurrect the Distributed Cache Service by executing the command:
Add-SPDistributedCacheServiceInstance 
Now let’s head to Central admin to fix a few things there.

11. Investigate the User Profile Synchronization Service. It was most likely stopped by the upgrade above and will need to be started again. I have ran into a rare instance where it reported that it was Started, but ended up finding that it actually wasn’t provisioned. If you find this to be the case, just go to the service and see that it is running normally. Kick off an incremental to make sure. Stop and Start the service again if you run into any issues.

12. Finally, let’s head to the Search Service Application to update the Content Sources and any Crawl Rules you may have. If you have any sources or rules that reference the name of the old server, these too will need to be updated with the new server name.
After all of this you may also want refresh your Health Analyzer list, the one that drives that little yellow or red bar across the top of Central Admin telling you that it has detected some issues. If you don’t have one of these displayed, AWESOME! It’s rare to find a farm that doesn’t have something in there. If you have any issues in there they’ll most likely be reporting these issues had occurred on the old server name. Once the rule runs again later on it’ll start saying the issue exists on both the old and new server names. It doesn’t hurt anything to leave it like this, but I like to go through and clean out that entire list and let it start fresh again with the new server name.
If you don’t want to wait for all of those rules to run again over time, you can force them all on the spot with the following command in the SharePoint Management Shell:

Get-SPTimerJob | where {$_.Title -like “Health Analysis Job*”} | Start-SPTimerJob

Saturday, 24 October 2015

SharePoint 2013 Search – Display Error: The display template has an error…

SharePoint 2013 Search – Display Error: The display template has an error…

Another silly one… If you are testing search while directly on the server, you may see the following issue:
Display Error: The display template had an error. You can correct it by fixing the template or by changing the display template used in either the Web Part properties or Result Types.
Automation server can’t create object (CoreRender: ~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_CommonItem_Body.js)
SNAGHTML6dcdf049[4]

A simple fix is to add the url of the site to the Local Intranet zone or Trusted Sites zone in Internet Explorer.
SNAGHTML6dd2b710

From Internet Options, select the Security tab, select Local Intranet zone (or trusted sites zone). Click Sites, and add the site under Advanced.


Tuesday, 20 October 2015

Search With FBA


  • Search With FBA


    ​​When you configure form based authentication sometime is is need that  you disable Integrated Windows Authentication. By doing so search does not work as per expectation and you may face error. If you check in crawl log you will saw following notification error message.
    Error:
    Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled. ( HttpStatusCode Unauthorized The request failed with HTTP status 401: Unauthorized. )

    Reason:

    This error will occur, when search engine tries to crawl the content using the URL but as there is a change in user identity server is unable to access database and server will reject the request.

    Solution:
    For SharePoint Search you need Integrated Windows Authentication for crawling the content database. To resolve this issue we need to create extended website. Follow below steps to extend 
    1.  Go to Central Administration and select your Form Based Authentication website and extend your website with integrated windows authentication enabled. Note, when you extend website you have different site in IIS.
    2. Now modify your search service application's content source and in content source give your extended website URL instead of live site url(Form-based authenticated site).
    3. Once you do that, click on content source and start full crawl. After crawl completes you will not face above error and search result is coming.
    4. If you check in your site now you may observe that search result is coming with extended site URL not with live site URL. To display live site URL open your Search Service Application and in the crawling section click on Server Name Mappings.
    5. From Server Name Mappings click on New Mapping.
    6. "In Address in index" give your extended site URL and "In address in search results" give your live site URL and click on Ok.
    7. Now once again click on content source and start full crawl. Now result will come with your live site URL.
     

     Please comment.