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.

  • 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. – Celophysis Jun 19 '18 at 6:28
  • it will be executed by SharePoint Admin.. without worfklow logic it works as expected.. – SRG Jun 19 '18 at 12:11
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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.