Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Thursday, October 6, 2011

Troubleshooting Search Service stuck in "Stopping State" ...

I have recently experienced this issue: search service stuck in "Stopping" state after last crawl.
After trying almost everything I had in mind:
  • restart IIS 
  • restarting the service from the services.msc 
  • trying to stop the service from Central Administration "Services in Server"
  • manually ending the process in Task Manager
  • trying power shell to stop the service using the command "Stsadm -o osearch -action stop"
  • trying to unprovision the content sources
And after all of the above I was still getting the error:

'stop' action failed. Additional information: Invalid search service unprovisioning: application 'Search Service Application' still has a ready component 'd9078ea1-0869-46f7-92d6-d89500f03abf-query-0' on server 'SPFARM2010'.

So I had to finally do enforce the security on the server - this way basically we "unlocked" the component that was faulting the provisioning of the search service. This was done by using the following power shell command:

psconfig.exe -cmd secureresources

Do not panic from the output message. It looks a bit scary:

SharePoint Products Configuration Wizard version 14.0.6009.1000. Copyright Microsoft Corporation 2010. All rights reserved.

Performing configuration task 1 of 5
Initializing SharePoint Products upgrade...

Waiting to get a lock to upgrade the farm.

Successfully initialized SharePoint Products upgrade.

Performing configuration task 2 of 5
Initiating the upgrade sequence...

Successfully initiated the upgrade sequence.

Performing configuration task 3 of 5
Securing the SharePoint resources...

* * *

After all of the steps are done, the farm will be online again.
Have in mind that this command also enforced the security on files, folders, and registry keys, but did the magic - our search service was back to it's normal state 

Tuesday, July 5, 2011

Tips & Tricks: quick deployment of .DLLs to GAC

Quick Tips & Tricks 
In this post I will try to put some of the tips & tricks we are using every day as a SharePoint developers. Hopefully you will find something that will help you and make your life a bit easier

Tip 1 - quick deployment of .DLLs:
One of the most used by me: PS script for quick deployment of DLLs in GAC and recycle the application pools. Every SharePoint developer is doing this at least 20 times per day. Of course we can use the deployment options of Visual Studio but usually when the change is in code behind we want a short way to replace only the current .dll and recycle the application pools with 1 click only (compared to CKSDev tools that will require at least 4 mouse clicks for the same):
    Step 1:  Create PowerShell script for deployment to GAC and app pool recycling. Let's name it RecycleCoreDLL.ps1 with the following code:

$appPoolName = "intranet.sharepointmasters.eu"
$appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | Where-Object {$_.Name -eq "W3SVC/APPPOOLS/$appPoolName"}
$appPool.Recycle()

& 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe' /u SharepointMasters.Portal.Core

& 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe' /i C:\Projects\SharepointMasters\SharepointMasters.Portal.Core\bin\Debug\SharepointMasters.Portal.Core.dll

& 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe' /u SharepointMasters.Portal

& 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe' /i C:\Projects\SharepointMasters\SharepointMasters.Portal\bin\Debug\SharepointMasters.Portal.dll

Here it is how it looks like:


All you need to change is the name of Application Pool and name of the assemblies. In this example I have 2 .DLL I want to deploy:
SharepointMasters.Portal.dll
SharepointMasters.Portal.Core.dll


    Step 2: create .bat file that will execute the PS script we just created. In my case I created   RecycleCore.bat with only 1 line in it:
         powershell.exe .\RecycleCoreDLL.ps1

That's it. Now  we have 1 click quick deployment

Monday, April 4, 2011

Configuration of the Microsoft SharePoint Server State Service using PowerShell

If you are trying to develop new InfoPath 2010 form and after deployment you are receiving the following errors:

"SharePoint 2010 The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator."

"InfoPath Forms Services not working due to invalid State Service configuration - Event 7898"


Then you need to configure the State Service. There are 2 options:

Option 1: Using PowerShell command
Open SharePoint Management Shell and type the following commands:

$serviceApp = New-SPStateServiceApplication -Name "State Service"

New-SPStateServiceDatabase -Name "StateServiceDatabase" -ServiceApplication $serviceApp

New-SPStateServiceApplicationProxy -Name "State Service" -ServiceApplication $serviceApp -DefaultProxyGroup

Option 2: Using "Farm Configuration Wizard" (however this approach is highly NOT recommended...) 
  • launch the "Farm Configuration Wizard" from Central Admin
  • click Start the Wizard 
  • select the State Service check box and click "Next"
  • click Finish

 One note here: if the State Service is greyed out, this means that it is already configured and the only way to change it is using PowerShell commands. Once configured it can not be retracted using Farm Configuration Wizard


Saturday, January 1, 2011

SharePoint 2010 Backup/Restore farm

Following article will show how to backup/restore SharePoint 2010 farms using shell script.
Power Shell Commands
Here are the shell commands that are used to backup/restore: 
Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential}
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite

Considerations and Prerequisites

First of all let’s start with little guidance about backup/restore procedures:
  • By design to restore a database is required at least 1 Full backup and the rest can be only Incremental backups. In order to save space we can perform Full backups on weekly bases and Incremental on backups on daily bases. However for large databases incremental backups are recommended.
  • Store a copy of backup files off-site
  • Backups should not be performed during operation hours to prevent data loss
  • Farm administrator account needed to perform the backup/restore operations
  • Valid AD accounts required to be used for SharePoint service accounts. Otherwise after restore the farm will not be operational. 

Backup procedure:

·         Open SharePoint Management Shell and type the command
    Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential}



Restore procedure

Open SharePoint Management Shell and type the command
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite
(command and parameters can be entered separately like below)



Then SharePoint will automatically list all Web Applications that are found in the backup:

Then SharePoint will ask user to provide credentials for the accounts that will be used to run the SharePoint Services. Depends on the installed services before the backup there are different accounts that needs to be provided. Few of the required accounts (listed as an example):
 - SP config account
- SP application pool account
- SP Search account
(below shown SP asking for Shared Services Application account)
 

Limitations of backup/restore

  • You cannot restore a multiple-server farm to a single-server farm or a single-server farm to a multiple-server farm
  • You cannot back up from one version of Microsoft SharePoint Server and restore to another version of SharePoint Server
  • Configuration and Central Administration content databases are not being restored by design from Microsoft SharePoint Server 2010 tools. There are 2 options to move  configuration databases (SP_Config):
o   Manually restore using SQL Manager
o   Install and configure SharePoint on the new environment, so it has its own configuration database and re-configure it.  LDP ha only few custom configurations that needs attention – Shared Services Provider (SSP), Search configuration and schedule, AD connector
  • Some of the service applications cannot be started automatically after  the restore operation and needs to be started manually (Using Central Administration or Power Shell)
  • Servers should have identical components installed! For example if you backup SharePoint farm with Enterprise Edition, Fast Search and BDC Connector configured, this backup cannot be restored on server with SharePoint Server Standard or Foundation or on server without Fast Search.

Useful links:
http://technet.microsoft.com/en-us/library/ee428316.aspx

http://technet.microsoft.com/en-us/library/ff607965.aspx