I cant believe this isnt working, I must be blind!! Please help me...

When I do

$blog = Get-SPWeb http://sp01.domain.com:8080/my/personal/user1/Blog

it is working quite well, but

foreach ($site in (Get-SPSite http://sp01.domain.com:8080/my/personal/* -Limit ALL))
    $blog = Get-SPWeb "$site/Blog"

throws an Exception like "Cannot find an SPSite Object that contains the following ID or URL: http://sp01.domain.com:8080/my/personal/user1/Blog."

It concatenates the URL right but cant get the SPWeb-Object... I believe the solution must be freaking easy, but Im not very experienced with Powershell :-(


OK, so PS is confused by you using your SPSiteobject as part of the URL, try this instead:

foreach ($site in (Get-SPSite http://sp01.domain.com:8080/my/personal/* -Limit ALL))
    $blog = Get-SPWeb ($site.Url + "/Blog") -ErrorAction SilentlyContinue

        #Do stuff here

I notice also that not all of my Personal sites has a "Blog" web, so you should do some "if not null"-check on the $blog in the foreach.

  • You are right, I just realized the problem with the SPSite object myself a few seconds ago :D – MartiniMoe Jul 10 '13 at 8:43
  • 1
    Thanks for the hint with the ErrorAction and the check on $blog! :-) – MartiniMoe Jul 10 '13 at 8:44

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.