Pages

Thursday, March 3, 2011

Deploy Web Part Through SharePoint 2010 Management Power Shell

Here this article you can see list commands which is useful for deploying the web part in Farm Level ,Web Application leve or site collection level.In Sharepoint 2010  l you can run below commands on SharePoint 2010 Management Power Shell.

Add Web Part to Central Administration And Web Application Level

Step 1 :  Open SharePoint 2010 Management Shell
        1. Verify that you meet the following minimum requirements: See Add-SPShellAdmin.
        2.On the Start menu, click All Programs.
        3. Click Microsoft SharePoint 2010 Products.
        4.Click SharePoint 2010 Management Shell.
        5. At the Windows PowerShell command prompt, type the following command:

// Add Solution to SharePoint 2010 Central Administration
Step 2 : Add-SPSolution -LiteralPath
    e.g  Add-SPSolution -LiteralPath C:\TestWebPart.wsp

//Install Solution @ Web Application
Step 3 :  Install-SPSolution -Identity -WebApplication
    e.g. Install-SPSolution -Identity "TestWebPart.wsp" -webapplication                                      "http://sitename"-GACDEployment

//Activate Site Collection Feature @ Web Application
Step 4 :  Enable-SPFeature -Identity -URL http://url
    e.g.  Enable-SPFeature -Identity ba5bc6d0-d2d9-4032-8334-7767aabb2414 -url                       http://sitename
   
    Enable-SPFeature -Identity TestWebPart_Feature1 -url http://sitename

Step 5 : On Completion of Step 3 , 4 and 5 your web part will be deploy on Web application and also feature is activate.


Same Way Remove Web Part from Web Application and Farm Level

-- Disable Feature from Web Application
Disable-SPFeature -Identity TestWebPart_Feature1 -url http://sitename

-- Remove Web Part from Web Application
Uninstall-SPSolution –Identity TestWebPart.wsp –WebApplication http://sitename
Remove-SPSolution–Identity TestWebPart.wsp

-- Remove Solution from Central Administration
Remove-SPSolution "TestWebPart.wsp"



 -- Uninstall Feature from Site Collection
Uninstall-SPFeature FeatureFolderName

--To Update Existing web part
Update-SPSolution –Identity TestWebPart.wsp –LiteralPath “C:\TestWebPart.wsp” –GacDeployment

Listing Features on Farm,SiteCollection

--To see all features for a Web Application:
    Get-SPFeature -WebApplication http://webapplicationName

--To see all features for a Site Collection:
    Get-SPFeature -Site http://sitecollection

--To see all features for a Site:
    Get-SPFeature -Web http://siteurl

If Share Point solutions do not retract or do no Deploying then Please use below Commands for survive

 
//Remove Solution from All Web Application
Uninstall-SPSolution -identity TestWebPart.wsp -allwebapplications

//Remove Solution from Central Administration using Force Command
remove-spsolution -identity {name of wsp file.wsp} -force

//Again Add Solution
add-spsolution -literalpath C:\{FULL file system location\name of wsp file.wsp}

//Install Solution using Force Command
install-spsolution -identity TestWebPart.wsp -webapplication http://Siteurl -GACDeployment -force


References :

http://www.sharepointanalysthq.com/2010/09/sharepoint-2010-powershell-feature-cmdlets-2/
http://patrickboom.wordpress.com/2010/05/31/using-powershell-to-deploy-sharepoint-solutions-wsp-2/
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/12/02/adding-and-deploying-solutions-with-powershell-in-sharepoint-2010.aspx

8 comments:

  1. Awesome!
    This is the unique site around the internet where you can find a complete step by step guide to deploy a Sharepoint WebpartQ.

    really really good!

    ReplyDelete
  2. I have a trouble, could you helpme?
    after all the steps the .webpart still in CustomWebParts/
    How can I remove it?

    ReplyDelete
  3. Hi Jaun Carlos,
    Can you please follow below steps :
    1. Disable feature from Site Collection
    e.g. Disable-SPFeature -Identity TestWebPart_Feature1 -url http://sitename
    2. Uninstall Feature with folder name
    e.g. Uninstall-SPFeature FeatureFolderName
    I think this two steps will remove feature from site ....

    ReplyDelete
  4. Hi,
    As I look around internet, there is no way to remove the .webpart file from erbpart gallery via SharePoint PowerShell commands.

    So I was playing a bit with PowerShell code and following some blogs ... finally I code this one:

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.WebPartPages")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")


    $url = Read-Host "Ingrese el nombre del servidor"
    $wps = Read-Host "Escriba el patrón del webpart"

    $SPSite = New-Object Microsoft.SharePoint.SPSite($url)


    $SPWeb = $SPSite.OpenWeb()
    $WebPartGallery = $SPWeb.Lists["Galería de elementos web"]

    $gall = $WebPartGallery.Items | select Name

    $count = $gall.Count
    $count
    for ( $i =0; $i -lt $count;$i++)
    {
    Write-Host "Actual:" $gall[$i].Name
    if ($gall[$i].Name -match $wps)
    {
    Write-Host "found"
    $WebPartGallery.Items.Delete($i)
    $SPWeb.Update()
    Write-Host "$wp deleted"
    }
    }
    $SPWeb.Dispose()

    Hope this helps to somebody

    ReplyDelete
  5. thanks lot for sharing content.

    ReplyDelete
  6. Hi,

    I'm able to deploy my solution successfully through the powershell,but not able to see my webpart when i try to add it,in the custom cateogery.

    ReplyDelete
  7. I'm able to deploy my solution successfully through the powershell,but not able to see my webpart when i try to add it,in the custom cateogery.

    ReplyDelete