0

I am not sure if this is supported so looking for some help.

workflow movesites
  {

    Param 
  (
   [Parameter (Mandatory=$true)] $sites,
   [Parameter (Mandatory=$true)] $movedToContentDb

  )
    InlineScript
    {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
    }
    foreach -parallel ($site in $sites)
    {

       $exists = (Get-SPWeb $site.url) -eq $null
          if($exists)
          {
            Write-host "Site doesn't exists"
          }
          else
          {
            Write-host "Moving site $($site.Url) to $contentDbName"
            Get-SPSite $site.url | Move-SPSite -DestinationDatabase $movedToContentDb -Confirm:$false
          }  
    }
  }

Basically, I am trying to invoke few SharePoint cmdlets in Parallel using Powershell Workflows but it seems Powershell Add-in doesn't get loaded at all and function throws error that Get-SPWeb is not recognized which is part of SharePoint powershell snap in.

Another challenge is foreach -parallel cannot be added into inlinescript as its not allowed.

2
  • what user will execute this? I was told that the Powershell Add-in can only be loaded by a Farm- or Server-Admin. In a comparable issue we had to rewrite our script and transform it into REST-calls. Commented Jun 19, 2018 at 6:28
  • it will be executed by SharePoint Admin.. without worfklow logic it works as expected.. Commented Jun 19, 2018 at 12:11

1 Answer 1

0

For parallel processes within PowerShell I use "Start-Job". eg:

$ScriptBlock = {
    param($one,$two)
    … do stuff
}
Start-Job -Name "Job" -ScriptBlock $ScriptBlock -ArgumentList $argOne,$ArgTwo| out-null

The script will execute the code within the script block and continue on. There are further commands available to monitor the progress of the job

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.