0

So far I am unable to access my list using a SharePoint site URL.

When I use get-spweb I get

"Cannot find an spweb object with Id or Url"

but I can easily type in the URL(https://test.contoso.com/visitors/siteName) in IE and see the site.

So therefore I can't do $list = $web.Lists to iterate through lists.

Now I can do get-spsite with the URL but then I cannot do anything at that point, I cannot use the $web.Lists nor can I use $site.title.

Any suggestions/help would be greatly appreciated!!!

8
  • Are you running this PowerShell from one of the SharePoint web front end servers or from a remote computer?
    – Thriggle
    Oct 17 '16 at 20:42
  • I am running it from the web front end server it is hosted on. @Thriggle Oct 17 '16 at 20:43
  • Are you able to get the site ($site = get-spsite http:...) and then access $site.RootWeb.lists?
    – Thriggle
    Oct 17 '16 at 20:45
  • @Thriggle I haven't tried that method yet, though I will. I have left the office for the day but I will follow up first thing tomorrow. Thanks for responding so fast by the way! Oct 17 '16 at 21:08
  • 1
    Found the issue. It was a new content database and they neglected to add the proper permissions. Womp Womp. Thanks for your time!!! Oct 18 '16 at 12:56
0

First of all, You should be aware of the difference between Get-SPWeb and Get-SPSite

So if the above link is a subsite, you should use Get-SPWeb, to iterate through list within a subsite , try to run the following script

  • Open SharePoint Managment PowerShell as administrator
  • Run the following code

Code

 $spweb = Get-SPWeb -Identity http://epm/workflow
 foreach($list in $spweb.Lists)
        {
          write-host $list.Title
        }

Output

enter image description here

If you need to iterate over all lists within a specific site URL in a site collection via Get-SPSite , you can use the following script

 $spsite = Get-SPSite http://rootsiteURL

foreach($spweb in $spsite.Allwebs)
        {
if ($spweb.URL -eq "http://fullsiteURL")

{
   foreach($list in $spweb.Lists)
        {
write-host $list.Title
}
}
}

Output

enter image description here

Note : If you tried to use Get-SPSite to access a subsite directly you will get the following error :

enter image description here

6
  • This still doesn't produce the site I am trying to connect to. It shows a lot of subsites but not the one I am looking for. Oct 18 '16 at 11:42
  • Dear @TheInexperiencedGamer I provide you more details with snapshot and different scenarios, only what you need to decide if your site is subsite use the first example , else use the second example , but I am sure the provided script should work as I mentioned above at output section ,so are you tried the second example, also please share your current code ! and Please don't hesitate to tell me if you need more clarification !! Oct 18 '16 at 12:30
  • I have tried it both ways, they do list a bunch of subsites but my subsite isn't listed despite doing an like statement to just hit the keyword when searching through the results sadly. I am starting to wonder if the DB this subsite is hosted on is set up correctly permission wise. Oct 18 '16 at 12:49
  • are you sure the above link is subsite ?! maybe you added a managed path with Wildcard inclusion as visitors and the above Url is a site collection, not subsite ? so in this case get-spweb will not be worked with you so try to run this code $spsite = Get-SPSite test.contoso.com/visitors/siteName foreach($spweb in $spsite.Allwebs) { if ($spweb.URL -eq "test.contoso.com/visitors/siteName") { foreach($list in $spweb.Lists) { write-host $list.Title } } } Oct 18 '16 at 12:59
  • It ended up being the new content database didn't have its permissions set up correctly. Thanks for your help though! Oct 18 '16 at 13:02
0

The content database the site was hosted on did not have correct permissions for the account trying to run the powershell.

This will cause the subsite to not properly show up when looking through all sites as well as it will cause an error if you try to use get-spweb.

Once the permissions were corrected the issue was resolved.

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.