0

In the PowerShell snippet below when I run the code with the line commendted out the script returns the list and all it's items. If I then swap the lines out and use the "ID" corresponding to that of the title and attempt to retrieve the list it fails to locate it. Is there something obvious I'm doing wrong here?

function CheckTaskInSites($task) 
{    
    $workspacesSites = $rootWeb.Lists[$workspaceslist]

    foreach($workspaceItem in $workspacesSites.Items)
    {       
        Write-host "1  Check task Title :" $workspaceItem.Title  
        Write-host $workspaceItem["Service ID"]
        #$web = $site.OpenWeb($workspaceItem.Title) 
        $web = $site.OpenWeb($workspaceItem.ID)                       

        CheckTaskIDInSite $task $web
        $web.Dispose()
    } 
}

Thanks

0

OpenWeb method does not work with the title, but with the URL of the site (web). See https://msdn.microsoft.com/en-us/library/ms474633.aspx:

strUrl

Type: System.String

A string that contains either the server-relative or site-relative URL of the Web site or of an object within the Web site. A server-relative URL begins with a forward slash ("/"), while a site-relative URL does not begin with a forward slash.

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.