Powershell script to stop services in Sp2016 Central Admin

Ganesh 46 Reputation points
2023-01-18T13:41:03.3866667+00:00

Hi Team,

Need help in preparing a PowerShell script for disabling few services in SharePoint 2016.

Purpose- We are upgrading Nintex from SP2013 to SP 2016, and we need to follow manual steps repeatedly due to more number of Nintex content DB's migrations every time. Below are the services I need to stop in sequence using PowerShell while migrating the DB every time.

  1. PS command to stop all services that host or inter operate with the SharePoint workflow engine.
  2. PS command to disable the Nintex Workflow Scheduler job
  3. PS command to Attach SharePoint content databases then End

Please help with a PS script to perform this steps will be helpful to save lots of time.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,027 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
598 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,577 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,231 Reputation points
    2023-01-19T07:20:52.65+00:00

    Hi @Ganesh,

    According to my research and testing, please refer to the following PowerShell:

    1.You can use the following PowerShell to stop all workflows on a list:

    $web = Get-SPWeb "https://your-sharepoint-site-url"
     
    #List Name
    $list = $web.Lists["Your-List-Name"]
     
    # Iterate through all Items and all Workflows on Items
    foreach ($item in $list.Items)
     {
       foreach ($wf in $item.Workflows)
         {
            #Cancel Workflows       
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf)     
         }
      }
    

    2.Unfortunately, there are currently no PowerShell commands have been found to disable the Nintex workflow scheduler job. We recommend that you contact the Nintex product for more professional help.

    3.Please use the following PowerShell to attach SharePoint content database:

    1. Verify that you have the following memberships:
    • securityadmin fixed server role on the SQL Server instance.
    • db_owner fixed database role on all databases that are to be updated.
    • Administrators group on the server on which you are running the PowerShell cmdlets.
    1. Open SharePoint Management Shell.
    2. At the PowerShell command prompt, type the appropriate command:
    3. To attach an existing content database:
    Mount-SPContentDatabase "<ContentDb>" -DatabaseServer "<DbServer>" -WebApplication http://SiteName
            
    

    Where:

    • <ContentDb> is the content database to be attached.
    • <DbServer> is the name of the database server.
    • http://SiteName is the name of the web application to which the content database is being attached.

    More information for reference:

    Cancel Workflows in SharePoint using PowerShell

    Attach or detach content databases in SharePoint Server

    Hope it can help you. Thanks for your understanding.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.