Wednesday, August 26, 2015

Powershell : Retrieve All Users in Site Collections under Web Application

Issue:

You are requested to retrieve all users in all site collections under a web application in SP2010/2013.

Solution:

Run this PowerShell script in Microsoft SharePoint Management Shell

#Header
"SiteCollectionURL;LoginName"
 
Try
{
 $WebApplicationUrl = "http://contoso.com"
 $webApplication = Get-SPWebApplication $WebApplicationUrl -ErrorAction SilentlyContinue;

 foreach($site in $webApplication.Sites){
  if($site.ReadOnly -eq $null -and $site.ReadLocked -eq $null -and $site.WriteLocked -eq $null)
  {
   continue;
  }
  else
  {
   foreach($user in $site.RootWeb.AllUsers){
    $site.RootWeb.URL +";"+ $user.LoginName;
   }
  }
 }
}
Catch [system.exception]
{
 "Error Occurred: $_"
}

Usually I will just simply save the code as in PS1 file and use this command to save it into CSV file.

file.ps1 > result.csv

And then use Excel to massage the data accordingly. Have fun!

Thursday, May 14, 2015

PowerShell : Download WSP from Central Administration (SP2007)

Issue:

You require to move a site to testing server, but when you import the backup, it throw error with feature.

Solution:

Run this PowerShell script to download the solution.

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local();
$wsp = $farm.Solutions.Item("solutionname.wsp").SolutionFile;
$wsp.SaveAs("E:\somefolder\solutionname.wsp");

Sunday, April 19, 2015

Web Application : Retrieve All Users Assigned to Groups in Site Collections (SP2007)

Issue:

You are requested to retrieve all users in all groups inside all site collections under a web application in SP2007. However SP2007 does not have Microsoft.SharePoint.Powershell assembly in it.

Solution:

Run this PowerShell script in Windows Shell

[System.Reflection.Assembly]::Load('Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c') | Out-Null

#Header
"SiteCollectionURL;GroupName;PermissionLevel;UserName;UserID"

#Specify the root site collection within the Web app
$Siteurl="http://contoso.com"; #change to your root site collection
$Rootweb=New-Object Microsoft.Sharepoint.Spsite($Siteurl);
$Webapp=$Rootweb.Webapplication;

#Loops through each site collection within the Web app
Foreach ($site in $Webapp.Sites)
{
    #Get all Site Collection Administrator
    foreach ($siteAdmin in $site.RootWeb.SiteAdministrators)
    {
        $site.URL+";Site Administrator;Full Control;"+$siteAdmin.Name+";"+$siteAdmin.Email
    }
    
    $groups = $site.RootWeb.SiteGroups
    foreach ($group in $groups) 
    {
        foreach ($user in $group.users) 
        {
            $site.URL+";"+$group.Name+";"+$group.Roles+";"+$user.Name+";"+$user.Email
        } 
    }
    
    $site.Dispose()
};

Usually I will just simply save the code as in PS1 file and use this command to save it into CSV file.

file.ps1 > result.csv

And then use Excel to massage the data accordingly. Have fun!

For SP2010 and SP2013 solution, click here.

Monday, February 16, 2015

Web Application : Retrieve All Users Assigned to Groups in Site Collections (SP2010 & SP2013)

Issue:

You are requested to retrieve all users in all groups inside all site collections under a web application.

Solution:

Run this PowerShell script in SharePoint Management Shell

#Header
"SiteCollectionURL;GroupName;PermissionLevel;UserName;UserID"

Try
{
 $WebApplicationUrl = "http://contoso.com" 
 $webApplication = Get-SPWebApplication $WebApplicationUrl -ErrorAction SilentlyContinue;
  
 if($webApplication -ne $null)
 {
  foreach($site in $webApplication.Sites){
   #Get all Site Collection Administrator
   foreach ($siteAdmin in $site.RootWeb.SiteAdministrators)
   {
    $site.URL+";Site Administrator;Full Control;"+$siteAdmin.DisplayName+";"+$siteAdmin.UserLogin
   }
   
   
   $groups = $site.RootWeb.SiteGroups
   foreach ($group in $groups) 
   {
    foreach ($user in $group.users) 
    {
     $site.URL+";"+$group.Name+";"+$group.Roles+";"+$user.DisplayName+";"+$user.UserLogin
    } 
   }
   $site.Dispose()
  }
 }
 else
 {
  Write-Host "Could not find Web Application $WebApplicationUrl" -ForegroundColor Red;
 }
}
Catch [system.exception]
{
 "Error Occurred: $_"
}

Usually I will just simply save the code as in PS1 file and use this command to save it into CSV file.

file.ps1 > result.csv

And then use Excel to massage the data accordingly. Have fun!

For SP2007 solution, click here.

Sunday, February 15, 2015

Search Service Application : Full Crawl Takes Forever to Complete.

Issue:

Search Service Application crawls never completed.


Solution:


  1. Check if there is any warning/error in your SSA Topology.
  2. If any, stop the crawling. Then, reset index. Once reset, check again the topology if the warning/error gone.
    1. If gone, do full crawl again.
    2. If persist, clear SharePoint Cache. You may refer to my earlier post here. Once cleared, reset index again, and the recrawl.
  3. If all steps done but it still takes long time to crawl; perhaps the SSA Index Component is not enough to cater your item. If you estimated number of documents in your SP2013 roughly more than 10k, the default SSA might not enough. You need to add more Index Component.

My web application has more than 1,000,000 documents to be crawled. Using default SSA setting (1 index component) cause my SSA to stuck in crawling for more than 17 days and never progressing. Increasing the Index Component to 4, and move the indexing folder to another Drive, makes my crawling complete within 6 days. (Well even still consider sucks, it is still better than 17 days, isn't it? :P)

Thursday, January 29, 2015

Excel Web Access : Graph Not Showing

Issue:

User claimed that he cannot see his graph in Excel when viewing it from browser.


Solution:

Font used by the graph is not web-compatible. Changing the font to web-compatible font (e.g. Verdana/Arial) solve the issue.

Sunday, January 18, 2015

Product Configuration Wizard : Stopped at Step 9 After Changed Farm Passphrase

Issue:

Farm passphrase changed using Powershell but not reflected when running Product Configuration Wizard. Throw error on Step 9.























Solution:


  1. Stop all SharePoint Timer Service in all SharePoint servers.
  2. While SharePoint Timer Service stopped, clear SharePoint cache in all SharePoint servers; one by one.
    1. Go to %SystemDrive%\ProgramData\Microsoft\SharePoint\Config. There will be 2 folders here. One has a GUID name, the other is not.
    2. Open the non-GUID folder which consists of PERSISTEDFILE files. 
      1. Delete all PERSISTEDFILE files.
    3. Open the GUID folder which consists of XML and INI file. 
      1. Open INI file and change the value to 1. Save it.
      2. Delete all XML files.
  3. Repeat step 2 to another SharePoint servers.
  4. Once completed, start again the SharePoint Timer Service.
  5. SharePoint will rebuilt again all XML in GUID folder. It will take a while to complete the process. I recommend you to leave it around an hour before proceed with next step.
  6. Check the GUID folder again. INI file value has now been changed, and all XML files has been rebuild.
  7. Re-run the Product Configuration Wizard. It should work by now.



p/s: You can also use this solution on your corrupted Search Service Application.