0

Trying to get a grasp on how the sharepoint object properties correlate to the sharepoint commands. I have 3 scripts that I am testing and 2 output the same display despite using Get-SPSite or Get-SPWebApplication:

#1

$siteurl = Get-SPSite "http://sharepoint/" -Limit All

# Get Site Collection
$webapp = $siteurl.WebApplication

foreach($site in $webapp.Sites) {
    Write-Host $site

    foreach($web in $site.AllWebs) {
        Write-Host `t$web
    }

}

Outputs the same results as

#2

$webapp = Get-SPWebApplication "http://sharepoint/"

foreach($site in $webapp.Sites) {
    Write-Host $site

    foreach($web in $site.AllWebs) {
        Write-Host `t$web
    }
}

Results

SPSite Url=http://sharepoint
SPSite Url=http://sharepoint/sites/appcatalog
SPSite Url=http://sharepoint/sites/devtest
SPSite Url=http://sharepoint/sites/publishing
...

So now if I run the following script, I seem to get more sites:

#3

# Get all Webapplictons
$SPWebApps = Get-SPWebApplication "http://sharepoint/"

# Get all sites
$SPSites = $SPWebApp | Get-SPsite -Limit all

foreach($SPSite in $SPSites) {
    # Get all websites
    Write-Host $SPSite
}

Results

SPSite Url=http://sharepoint:1234
SPSite Url=http://sharepoint
SPSite Url=http://sharepoint/sites/appcatalog
SPSite Url=http://sharepoint/sites/devtest
SPSite Url=http://sharepoint/sites/publishing
SPSite Url=http://sharepoint:27741
SPSite Url=http://sharepoint:27741/personal/...
SPSite Url=http://sharepoint:27741/personal/...
SPSite Url=http://sharepoint:27741/personal/...

What am I missing? How can I correlate the properties such as .Sites,.AllWebs to their objects such as Get-SPSite and Get-SPWebApplication?

1 Answer 1

0

I found the error in your code. Run the below code( from method #3) it will return the same output

# Get all Webapplictons
$SPWebApps = Get-SPWebApplication "http://sharepoint/"

# Get all sites
$SPSites = $SPWebApps | Get-SPsite -Limit all

foreach($SPSite in $SPSites) {
    # Get all websites
    Write-Host $SPSite
}

Basically on the this line $SPSites = $SPWebApp | Get-SPsite -Limit all You miss the leading s in front of the $spwebappS...this command get all the sites in the farm( sharepoint & sharepoint:27741). while your other two method return the sites collection from a specific web app which is http://sharepoint/

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.