SharePointCommunity
Die deutschsprachige Community für SharePoint, Microsoft 365, Teams, Yammer und mit Azure

Sponsored by

Willkommen im Forum Archiv.
Einträge sind hier nicht mehr möglich, aber der Bestand von 12 Jahren SharePoint-Wissen ist hier recherchierbar.




Re: Workflow per PowerShell starten

Dieser Beitrag hat 0 Antworten

Ohne Rang
253 Beiträge
BBB erstellt 18 Mai 2015 13:04
SchlechtSchlechtIn OrdnungIn OrdnungDurchschnittDurchschnittGutGutSehr gutSehr gut

So sieht mein Script aus:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
  Add-PSSnapin Microsoft.SharePoint.PowerShell
}
#Site and List 
$SPAssignment = Start-SPAssignment
$web = Get-SPWeb "" -AssignmentCollection $spAssignment
$site = Get-SPSite ""
$listName = ""
$web.AllowUnsafeUpdates = $true;
 
#Output file
$Today = Get-Date -Format "dd-M-yy"
$outFile = "c:\CancelWorkflowScript-Log-$Today.txt"
 
#Workflows to Remove
$wfToStart= "Workflow"
 
#List Name 
$list = $web.Lists[$listName];
 
#Workflow Manager
$manager=$site.WorkFlowManager
$association=$list.WorkFlowAssociations | where {$_.Name -eq $wfToStart}

 
# Iterate through all Items in List and all Workflows on Items. 
 #Filtered List
 Write-Host "Restarting workflows.."
 foreach ($item in $list.Items) {
  if ($item["Status"] -eq "Abgeschlossen") {
   $data=$association.AssociationData
   $wf=$manager.StartWorkFlow($item,$association,$data)
   Write-Output "$wftoStart started on " $item.Name | Out-File $outFile -Append
  }
  else {
   Write-Output $item.Name " - is completed " | Out-File $outFile -Append
 
  }
 }
Write-Host Finished.
$web.Dispose()
$site.Dispose()

An der gelb markierten Stelle entsteht der Fehler.