Tuesday, May 6, 2014

Mostly used powershell command in SharePoint 2013/ SharePoint 2010

Hi Friends,
This blog is about commonly used power shell command used in SharePoint 2013 and SharePoint 2010. I have tested all these commands in SharePoint 2013.

Power shell is executed from SharePoint 2010/2013 management Shell.
è Adding WSP :
ð Farm solution:
               Add-SPSolution -LiteralPath <Path of wsp>
  Eg: Add-SPSolution -LiteralPath c:\contoso_solution.wsp
 
ð Sandbox Solution:
               Add-SPUserSolution –LiteralPath < path of wsp> -site < site ulr>

è Deploy Installed solution
ð Farm Solution:
               Install-SPSolution -Identity <Web part Name.wsp> -GACDeployment
 Eg: Install-SPSolution -Identity contoso_solution.wsp –GACDeployment
 
ð Sandbox Solution:
               Install-SPUserSolution –identity wspfilename.wsp –site <site url>
Eg: Install-SPUserSolution –identity wspfilename.wsp –site <site url>

è Update Existing
ð Farm Solution:
               Update-SPSolution -Identity <wsp name> -LiteralPath <WSP Path> -GACDeployment
 Eg: Update-SPSolution -Identity my.wsp -LiteralPath c:\my.wsp –GACDeployment
 
ð Sandbox Solution:
      Update-SPUserSolution -Identity contoso_solution.wsp -Site http://sitename -ToSolution contoso_solution_v2.wsp
    Eg: Update-SPUserSolution -Identity my.wsp -Site http://sitename -ToSolution myv2.wsp
 
è Uninstall Solution :
ð Farm Solution:
Uninstall-SPSolution [-Identity] <SPSolutionPipeBind> -WebApplication <SPWebApplicationPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <String>] [-Confirm [<SwitchParameter>]] [-Language <UInt32>] [-Local <SwitchParameter>] [-Time <String>] [-WhatIf [<SwitchParameter>]]
    Eg:     Uninstall-SPSolution –Identity http://sitename contoso_solution.wsp
 
ð Sandbox Solution:
Uninstall-SPUserSolution [-Identity] <SPUserSolutionPipeBind> -Site <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
 Eg: Uninstall-SPUserSolution -Identity my.wsp -Site http://sitename
 
è Remove Solution:
ð Farm Solution:
Remove-SPSolution [-Identity] <SPSolutionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-Language <UInt32>] [-WhatIf [<SwitchParameter>]]
Eg:  Remove-SPSolution -Identity contoso_solution.wsp
ð Sandbox Solution:
Remove-SPUserSolution [-Identity] <String> -Site <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
Eg:  Remove-SPUserSolution -Identity contoso_solution.wsp -Site http://sitename

è Get List of Solution
ð Farm Solution:
                        Get-SPSolution
ð Sandbox Solution:
                        Get-SPUserSolution –Site <site name>

è Install Feature:
ð Farm Solution:
Install-SPFeature [-Path] <String> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg:  Install-SPFeature -path "MyCustomFeature"

è Enable Feature: The Enable-SPFeature cmdlet enables an installed feature at the given scope.
ð Farm Solution:
Enable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-PassThru <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg:  Enable-SPFeature -identity "Feature Folder path" -URL http://somesite

è Deactivate Feature:
ð Farm Feature:
Disable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-Url <String>] [-WhatIf [<SwitchParameter>]]
Eg:  Disable-SPFeature –identity "MyCustom" -URL http://somesite

è Uninstall/ Delete Feature: The Uninstall-SPFeature cmdlet removes the specified feature definition from the collection of feature definitions in the farm.
ð Farm Solution:
Uninstall-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg: Uninstall-SPFeature -Identity "MyCustomFeature"

è Get List of active features: It displays feature name and corresponding ID:
        Get-SPFeature -Site http://SharePointSite/


è To Delete unused web parts from Solution Store: .webpart file is not deleted from web part gallery after executing above commands, user needs to run bellow command to delete (.webpart) from gallery.

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery = '<Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">TestgiriWebPart_GiriWebPart.webpart</Value></Eq>  </Where>'
$spQuery.Query = $camlQuery

$site = Get-SPSite -Identity "http://win-ua50t4mr5s4"
$webpartgallery = $site.GetCatalog( [Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog)
$webparts = $webpartgallery.GetItems($spQuery)
$webparts[0].Recycle()

è To get details about the feature and web application: If you are not sure what Web the feature is activated in, run the following:
                Get-SPSite http://SharePointSite/ | Get-SPWeb -Limit ALL | %{ Get-SPFeature -Web $_ } | Sort DisplayName -Unique | FT DisplayName,Id

è Delete Feature:
      Uninstall-SPFeature <Feature ID>

è To See List of solutions in Solution store:
Stsadm  -o EnumSolutions


è Backup and Restore:
ð Backup SharePoint FARM:
            Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential} [-Verbose]
Eg: Backup-SPFarm c:\SPBackup\myfarm.bak –BackupMethod Full

ð Backup Site Collection:
Backup-SPSite -Identity <SiteCollectionGUIDorURL> -Path <BackupFile> [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
Eg: Backup-SPSite –identity http://siteName/ -path c:\mysite.bak –force

è Restore Backup
ð Restore Server Farm:
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite [-BackupId <GUID>]
Eg: Restore-SPFarm -Directory \\file_server\share\Backup -BackupId 12345678-90ab-cdef-1234-567890abcdef -RestoreMethod new -ConfigurationOnly

ð  Restore Site Collection:
  Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeader HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]
Eg:  Restore-SPSite –identity http://mysite  -path c:\myback.bak -force

è SharePoint list backup: To backup SharePoint list we need to use SharePoint management shell
ð  Exporting List
Export-SPWeb http://www.domain.com -itemurl "/Lists/NameList" -path "c:\test.cmp”
ð  Importing List:
Import-SPWeb http://www.domain.com -Path "c:\test.cmp"

Commonly used power shell command:
ð  Removing Web application
            Remove-SPWebApplication -identity http://sitename –Confirm

ð  Delete Web Application Pool
            Remove-WebAppPool  -name ‘applicationPoolName’
ð  Remove Web Application , Content Database and IIS Application Pool
Remove-SPWebApplication http://sitename -Confirm -DeleteIISSite -RemoveContentDatabases
  
Export list:
# specify the site URL to export

$web = Get-SPWeb "http://testsite:9000"

# specify output folder to store exported lists

$path = "c:\ListBackup\"

foreach($list in $web.lists)
 {
 "Exporting " + $list.RootFolder.URL
 Export-SPWeb $web.URL -ItemUrl $list.URL -path ($path + $list + ".cmp") -nologfile
 }

Export-SPWeb http://tawasul/IT/ISC/ -ItemUrl "/Lists/List_Name" -path "c:\ExportISC\List_Name.cmp"
Export-SPWeb http://mysite/sites/KPI/ -ItemUrl "/Lists/" -path "c:\Export_KPI\List_Name.cmp"
è    Re-Indexing SharePoint List:
UPDATE <Content DB>.dbo.AllListsAux set NextAvailableId=1 where ListID='<GUID>'
eg:
UPDATE WSS_RQMS.dbo.AllListsAux set NextAvailableId=1 where ListID='{500440F9-EEFE-4659-9D33-B90F68404DD4}'
è    Adding Column to existing SharePoint List using powershell:
param([string]$workspaceUrl)
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{
$site = SPSite($workspaceUrl)
$web = $site.RootWeb
$spList = $web.Lists["YourList"]
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("YourColumn",$spFieldType,$false)
$spList.Update()
}
)
To Execute: Save this file in your local drive execute as bellow:
PS C:\Administrator> .\YourScript.ps1 -workspaceUrl "yoururl"
Eg: PS C:\Administrator> C:\MyScript.ps1 -workspaceUrl "http://mymachinename:9000"

è    Create database from power shell:
New-SPConfigurationDatabase [-DatabaseName] <String> [-DatabaseServer] <String> [[-DirectoryDomain] <String>] [[-DirectoryOrganizationUnit] <String>] [[-AdministrationContentDatabaseName] <String>] [[-DatabaseCredentials] <PSCredential>] [-FarmCredentials] <PSCredential> [-Passphrase] <SecureString> [-AssignmentCollection <SPAssignmentCollection>]

è    Changing Site Logo:

$sitename= "http:// dev/sites/SiteName"
$sitelogo= "http:// dev/Site Assets/sitelogo.jpg"
$site=new-object Microsoft.SharePoint.SPSite($sitename)
$web=$site.OpenWeb()
$web.SiteLogoUrl=$sitelogo
$web.Update()
$site.Dispose()

è    Cleanup Deleted Database from SharePoint server:
ð    Display list of all database
Get-SPdatabase
ð    This will list all databases in SharePoint that no longer exist on the database server.
Get-SPDatabase | where {$_.exists -eq $false} :
ð    Remove all orphan database:
Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}

è    Get List of Application Pool:
ð    Get list of application Pool:
Get-SPServiceApplicationPool
ð    Delete Application Pool:
Remove-SPServiceApplicationPool-Identity <Name of the application pool>
è    Change Master Page :
$web = Get-SPWeb http://sharepoint
$web.CustomMasterUrl = "/_catalogs/masterpage/seattle.master"
$web.MasterUrl = "/_catalogs/masterpage/ seattle.master"
$web.Update()
è    Get List of Web Application in a Farm:
Get-SPWebapplication
è    Get List of Site collection in a Web Application:
Get-SPWebApplication <WebAppURL> | Get-SPSiteAdministration -Limit ALL| Select url,Title
Eg: Get-SPWebApplication  http:// dev/ | Get-SPSiteAdministration -Limit ALL| Select url,Title
è    List all the Web Application and Site collection and sub sites
Get-SPSite
è    Remove a WebApplication, content database, Application Poo:

Remove-SPWebApplication http://win-2k8-dc7:8081 -Confirm -DeleteIISSite –RemoveContentDatabases
è    To Create new Web Application:

$ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos
New-SPWebApplication -Name "WEBAPP" -Port 80 -URL "http://WebAppqa" -ApplicationPool "WEBAPPApplicationPool" -ApplicationPoolAccount (Get-SPManagedAccount "domain\spadmin") -DatabaseName "WSS_Content_WEBAPPRootDB" –AuthenticationProvider $ap
è    To attached SharePoint content database from one server to another server:
ð    Dismount  database from source server:
Dismount-SPContentDatabase [-Identity] <SPContentDatabasePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
Eg:
Dismount-SPContentDatabase <database name>
ð    Mount Database to new server:
Mount-SPContentDatabase "<ContentDb>" -DatabaseServer "<DbServer>" -WebApplication http://SiteName
è    Crate Site collection:
New-SPContentDatabase -Name WSS_Content_WEBAPP_TestSite  -WebApplication http://WebApp:8080/
New-SPSite http://WebApp:8080/sites/TestSite -OwnerAlias "domain\sAdmin" -ContentDatabase WSS_Content_WEBAPP_TestSite-Name "TestSite" -Template "PROJECTSITE#0"

Regards
Gireesh Painuly..


Saturday, February 8, 2014

How to Debug Visual Studio Solution in SharePoint

Hi friends, this post about debugging SharePoint solution which are created using Visual Studio 2010 or Visual Studio 2012.
When we create any Visual studio solution for SharePoint and deploy it’s WSP on any environment like QA Environment, Staging and production then some time we require to debug the solution to investigate execution process.
Some time even in Development environment debugging SharePoint site takes much time to reach execution debug point. In such cases we can debug SharePoint solution using IIS process method.
To start debug any SharePoint portal you need to check following things.
 è Check whether your updated solution is deployed in environment (other than Dev Env)
 è Get your latest Visual studio project solution which is deployed in SharePoint site.
Do following step to debug your solution:
iis6.0:
  ð  Run command prompt and navigate to following location:
  c:\Windows\System32>
  ð  Type below command:
     c:\Windows\System32>iisapp.vbs
  ð   Above command will display list of processes id with application pool
  ð  You can easily find the SharePoint portal address with application pool on command prompt.
IIS 7.5:
  ð  Run command prompt and navigate to following location:
    c:\Windows\system32> cd inetsrv
    c:\Windows\system32\inetsrv>appcmd list wp
  ð  Above command will display list of processes id with application pool
  ð  You can easily find the SharePoint portal address with application pool on command prompt.
 è Now go to your Visual studio solution => Debug=>Attach Process
 è Here you will find the list of process id where you need to attach the process id of you SharePoint application pool
 è Once correct process id is attached go to your SharePoint Site and click on the event that you want to monitor.


Related links:
Debug SharePoint Applications 
how to debug sharepoint code 

Happy Debugging 

Sunday, December 1, 2013

The term 'Select-Object' is not recognized as Name of a cmdlet

Hi friends,
This error usually occurs in SharePoint 2013 while running SharePoint 2013 Management Powershell.



This happens due to change in environment variable of “PSModulePath” in windows environment variables
To make it workable you need to perform following actions:
è Log in to the SharePoint Server
è Right click on my computer-> Properties-> Advance System Settings -> Environment Variable
è Scroll your System Variable section-> (PSModulePath) you will find below entry in Variable Value section 
ð  PS Module path:
;c:\Program Files\AppFabric 1.1 for Windows Server\PowershellModules
è append below path in seme line:
;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
è It should look like below:
;c:\Program Files\AppFabric 1.1 for Windows Server\PowershellModules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
 That’s it, now run SharePoint 2013 management shell as administration and you will not see the error

Happy Configuration.....






Saturday, August 24, 2013

Creating Custom Log Out page in SharePoint 2010/ 2013.

Hi friends,
This post is about how to create Custom Log out page in SharePoint. This customization is required when you implement FBA ( Form Based Authentication) or Mix mode authentication in SharePoint. When FBA is implemented with custom Log-in, it does not clear authentication Cookies automatically so to clear authentication cookies we need to do some customization. This customization is done using custom logout page where some block of java-script code is written:

This block of code also helps to prevent error while logging out using FBA.

Following steps are carried out while creating custom log out page in SharePoint with

1.       First Create a logout.aspx using SharePoint Designer
è Open your site using SharePoint designer-> Go to site pages->click on Page button on top ribbon and select ASPX page.
è It will create an aspx page in site pages rename it to Logout.aspx
è Double click on page, it will open page designer, Check Out the page and click on edit file link to open in edit mode.
è Add page title to: Lout out
è Add bellow Script in <head> section:
<script type="text/javascript">
function LogOutBodyOnLoad()
{
try
{
   /* Note : this command is support with only IE  */
  document.execCommand("ClearAuthenticationCache",false);
  window.close(); // It asks to close browser after logout.
  }
  catch (e) { }
 window.location='/_layouts/signout.aspx'; // Redirects to sign out page of SharePoint.
 }
 </script>
è In <body> section change as bellow:
<body onload="LogOutBodyOnLoad ()">
è Check in your Logout.aspx page after performing above changes.
è Next you need to call this Logout.aspx on click of Log out button on Welcom.aspx page that is master page of your site.
è Before change master page you need to check which master page is used by your application to check it go to Site Action->Site setting-Look and feel->Master page. It will show you which master page is used in your application.
è Go to SharePoint Designer -> click on master page in left navigation -> take copy of your master page. If you are working in SharePoint 2013 then you will get ( oslo.htm, oslo.master, seattle.html and seattle.master). Open only ( .html) page in designer and add below script on head section of master page which your application is using. ( check out your master page before editing )
<script type="text/javascript" src="/_catalogs/Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){$("#zz4_ID_Logout").attr("onMenuClick","STSNavigate2(event,'/Site Pages/Logout.aspx');");});
</script>
è Add jquery fie to _catelogs/Scripts using SharePoint designer. If script folder does not exist in _catelogs crate it and add jqury file in it. Check proper version of jquery file with the master page tag.  Jquery file is added in _catelogs using SharePoint designer.
è If you are using SharePoint designer then Id of Logout control may be different, it may be zz3_ID_Logout or zz4_ …. So to get right ID login to your portal and check Source of page, Search for Log out and get right control ID. Replace control ID in Master page’ javascript tag with the right one.


è That’s it now you can login in to your portal and can identify title of log out page after clicking log out button. This could is mainly written to clear authentication cookies after logout.

That's it.. Fell free to ask any question regarding this post.

Happy Coding 
Regards
Gireesh Painuly..

Sunday, June 9, 2013

Save Site as Template is not visible in Site Settings in SharePoint 


Hi Friends,

This blog is about enabling “Save as Site Template” in SharePoint 2010 and SharePoint 2013.
Save Site as Template is only visible if you have publishing infrastructure disable in your site collection Administrator and site Action.
By default “save site as Template” is visible in Site Settings under <Site Action > In SharePoint 2010 and SharePoint 2013

SharePoint 2013









SharePoint 2010










If “Save as Site Template” is not visible in your Site actions perform following Actions:
1-> First go to your Site settings
  è Site Action -> Manage Site features Click on SharePoint Server Publishing and deactivate it if it is  enabled.
     2-> Site Collection Administrator -> Site Collection Feature (Deactivate following Feature)
  è Cross-Site Collection Publishing    ( optional)  
  è SharePoint Server Publishing Infrastructure
    3-> If you had publishing feature enabled and you have just deactivated it then you will not able to see Save as Site Template after deactivating publishing infrastructure. 
    4-> You need to open your site using SharePoint designer. After opening site using SharePoint designer just go to Site Tab, Site Option button on the right most part of panel, Click on it, a window will open as bellow:





















Happy Codding...

Thanks For Reading....

Gireesh Painuly.


Related Search: 

Enable Save Site as Template in SharePoint 2010
Enable Site as Template in SharePoint 2010.
Site as Template is not visible in Site Settings
Site as Template is not visible in Site Collection  
Site as Template is not visible in Site Action
Save Site as Template Option is Missing in SharePoint 2010.