What is the difference between SPWeb and SPSite? I have this code using SPWeb

$web = Get-SPWeb http://mysite 
ForEach($list in $web.Lists)
    if($list.BaseType -eq "DocumentLibrary")
        Write-Host $list.Fields
        if($list.Fields.ContainsField("marking") -eq $true)
            Write-Host "found" $list.Title

Which doesn't produce the right result, as apparently GPMS marking is not a column for a Document Library. But when I use this code using SPSite

Get-SPSite mysite |
Select -ExpandProperty AllWebs |
Select -ExpandProperty Lists |
where {$_.GetType().Name -eq "SPDocumentLibrary"} |
Select -ExpandProperty Fields |
Select Title | out-file test.txt

This has the so called marking column that I want to search for in the previous bit of code. Is there anyway of changing the previous bit of code so it does find the marking column?

  • 1
    SPSite represents a site collection while SPWeb represents a specific web site within the site collection. Normally, you open a specific SPWeb within SPSite via SPSite.OpenWeb(). You can use SPSite.AllWebs to enumerate existing webs, or SPSite.RootWeb.
    – w128
    Commented Jun 6, 2014 at 10:39
  • So your site name is same for both the cases??
    – Aanchal
    Commented Jun 6, 2014 at 11:05

2 Answers 2


You need to start of with the tree ;)

You have a farm (SPFarm) and in that farm you have many web applications (SPWebApplication), within one of those web applications you would have a site collection(SPSite) and within that site collection you would have many sub sites (SPWeb) that hold many sites (SPWeb) or in your case webs (SPWeb) under the site colleciton.

from a url perspective:


coding wise in your case your calling an spweb on a toplevel spsite. coding wise if you want to get the spweb object you need to note that its rootweb ;) as your mysite is based at the sitecollection and not at the subsite or site level!


$site = Get-SPSite http://mysite

Your example is a bit ambiguous. One example deals with just 1 SPWeb at a specific location, the other with an SPSite, as you say, but you pipe ALL the subwebs of that SPSite (and even subwebs within subwebs I believe). So it may be that you find the field in a completely different SPWeb under the SPSite, where before you were just checking 1 specific SPWeb under the SPSite.

So most likely that field was not deployed to "http:// skynet" but a different SPWeb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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