Wednesday, 18 March 2015

PowerShell Scripts

PowerShell Commands

WSP (Windows Solution Package) Deployment steps:

  1. Add Solution
    • Add-SPSolution WSP_File_Path
  2. Install Solution
    • Install-SPSolution -Identity WSP_Name -WebApplication Web_App_URL -GACDepyment
  3. Update Solution
    • Update-SPSolution -Identity WSP_Name -LiterelPath WSP_File_Path
  4. Uninstall Solution
    • Uninstall-SPSolution -Identity WSP_Name -WebApplication Web_App_URL
  5. Remove Solution
    • Remove-SPSolution -Identity WSP_Name
Examples:
  • Add-SPSolution c:\code\SharePointProject2\bin\debug\SharePointProject2.wsp
  • Install-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 -GACDeployment
  • Update-SPSolution –Identity SharePointProject2.wsp –LiteralPath c:\code\SharePointProject2\bin\debug\SharePointProject2.wsp –GACDeployment
  • Uninstall-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010
  • Remove-SPSolution –Identity SharePointProject2.wsp
Site BackUp and Restore

BackUp 

To take the backup use the below commands
  • Backup-SPSite Site_URL -Path Location_And_name_Of_Bacup_File
  • Get-SPSiteAdministration Site_URL | Backup-SPSite -Path Location_And_name_Of_Bacup_File
Examples:
  1. Backup-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
  2. Get-SPSiteAdministration http://server_name/sites/site_name | Backup-SPSite -Path C:\Backup\site_name.bak
Both examples above perform the same operation, but different ways to do the Backup.

Restore

To do restore use the below commands
  • Restore-SPSite Site_URL -Path Bacup_File_Path
  • Restore-SPSite Site_URL -Path Bacup_File_Path -Force -DatabaseServer SQLServ1 -DatabaseName SQLBD1
Examples:
  1. Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
  2. Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak -Force -DatabaseServer SQLBE1 -DatabaseName SQLDB1
This example restores a site collection backup from the backup file C:\Backup\site_name.bak, but overwrites the existing site collection at http://server_name/sites/site_name while specifying that the site collection must be stored in a specific content database

Attach an existing content database to the farm in SharePoint

  • Mount-SPContentDatabase "MYDatabse" -DatabseServer "MyServer" -WebApplication WebApp_URL
Exaple:
  1. Mount-SPContentDatabase "MYDatabse" -DatabseServer "MyServer" -WebApplication http://sitename
Add a DLL to the GAC using PoweShell

  1. Run the SharePoint PowerShell console as Administrator
  2. Enter the following PowerShell
    • Set-location "c:\temp" [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") $publish = New-Object System.EnterpriseServices.Internal.Publish $publish.GacInstall("c:\temp\RemoveMicrosoftOfficeProtocolDiscoveryLoginBoxModule.dll") Iisreset
  3. To add an element in web.config
    • You can just add the following line as the first httpModule inside after the element in web.config:
    • <add name="RemoveMicrosoftOfficeProtocolDiscoveryLoginBoxModule" type="TheBlackKnightSings.RemoveMicrosoftOfficeProtocolDiscoveryLoginBoxModule, RemoveMicrosoftOfficeProtocolDiscoveryLoginBoxModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1537c6b9f16ad88e" />

No comments:

Post a Comment