none
trying to run powershell script to access sharepoint workflows RRS feed

  • Question

  • All responses are appreciated.    We have an application server that has sharepoint 2007 version 12. pointing to a different server with SQLSERVER 2008  for the database.

    The app server has powershell 2.0 on it.  I found the following script and modified it slightly for our site but keep getting the error below.  We can access sharepoint from the server thru explorer with no problems but not with the powershell script.  Can someone enlighten me on what is wrong?

    #Load SharePoint 2007 Assemblies
    [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null
    $C = Get-Credential

    $siteurl=
    $site=new-object ($siteurl)

    #Initialize Workflow Count variable
    $workflowcount = 0

    #Foreach loop to loop through all webs, and lists with workflow associations, and exclude workflows that have previous versions and write findings to .csv file.

    function Get-Workflows()
    {
        foreach($web in $site.AllWebs)
        {
                foreach($list in $web.Lists)
                {
                    foreach($wf in $list.WorkflowAssociations)
                    {
                            if ($wf.Name -notlike "*Previous Version*")
                            {
                                $hash = @{"[URL]"=$web.Url;"[List Name]"=$list.Title;"[Workflow]"=$wf.Name}
                                 New-Object PSObject -Property $hash | Sort-Object

                            }
                    }
                }
        }
    }

    foreach($web in $site.AllWebs)
    {
        foreach($list in $web.Lists)
        {
            foreach($wf in $list.WorkflowAssociations)
            {
                if ($wf.Name -notlike "*Previous Version*")
                {
                   $workflowcount += 1
                }
            }
        }
    }

    Get-Workflows | Export-csv c:\workflows.csv
    "Workflow Count " + $workflowcount >> E:\workflows.csv

    $site.Dispose()

    error text:

    PS H:\> .\sharepoint.ps1

    New-Object : Exception calling ".ctor" with "1" argument(s): "The Web application at http: could

    not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system a

    dministrator may need to add a new request URL mapping to the intended application."

    At H:\sharepoint.ps1:5 char:17

    + $site=new-object <<<<  Microsoft.SharePoint.SPSite($siteurl)

        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException

        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.

    At H:\sharepoint.ps1:48 char:14

    + $site.Dispose <<<< ()

        + CategoryInfo          : InvalidOperation: (Dispose:String) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull

    • Moved by Bill_Stewart Friday, December 30, 2016 9:05 PM This is not "fix/debug this organization-specific script" forum
    Friday, November 18, 2016 8:41 PM

All replies