2

When trying to run this Powershell Script I'm getting an error:

Param(
        [parameter(Mandatory=$true)]
        [alias("url")]
        $siteurl,
        [parameter(Mandatory=$true)]
        [alias("list")]
        $listname,
        [parameter(Mandatory=$true)]
        [alias("workflow")]
        $workflowname
        )

    $site = Get-SPSite $siteurl
    $web = $site.RootWeb;
    $list = $web.Lists[$listname];
    $statusChoices = $list.WorkflowAssociations.GetAssociationByName($workflowname,[System.Globalization.CultureInfo]::CurrentCulture).BaseTemplate.GetStatusChoices($web);

    $countChoices = $statusChoices.count;

    Write-Host 'Status Choice count - ' $countChoices;

    $i = 0;

    while($i -lt $countChoices)
    {
      Write-Host $i ' - ' $statusChoices[$i];
      $i++;
    }

Error:

You cannot call a method on a null-valued expression.
At E:\PowerShellScript\test.ps1:12 char:65
+ $statusChoices = $list.WorkflowAssociations.GetAssociationByName <<<< ($workf
lowname,[System.Globalization.CultureInfo]::CurrentCulture).BaseTemplate.GetSta
tusChoices($web)
    + CategoryInfo          : InvalidOperation: (GetAssociationByName:String)
   [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
  • did you specify all parameters ($siteurl, $listname and $workflowname) in command line properly? – Atish Dipongkor - MVP Nov 18 '15 at 12:22
0
$site = new-object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb();

Changing these two lines helped.

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.