I am just getting started with a basic tutorial to Sharepoint and Powershell, following the following commands while in Powershell on my SP server:

$mysite = new-object Microsoft.sharepoint.SPSite($site)

Up to here works fine, I get a response from gettype But $mysite.Allwebs does not have anything.


Does not even show zero. So it looks like I a missing some important piece. Any ideas?

Thank you. Daniel Williams


Your tags indicate that you're working with SharePoint 2010 but your PSH looks like you're working with SharePoint 2007.

If you're working with SPT 2010, there are about 500 custom PSH cmdlets.

As for the code you have, try this:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null

$site = New-Object -typename "Microsoft.SharePoint.SPSite" -argumentlist "http://localhost"

The out-null just throws the output away that otherwise goes to the console (in case you're wondering).

| improve this answer | |
  • That worked, thank you. What part of my script looks like SP 2007? – Daniel Williams Jun 3 '11 at 0:28
  • 1
    All the stuff you're doing getting the Microsoft.SharePoint namespace is stuff I have to do when working with SPT 2007. It's not necessary in SPT 2010 as there's a PSH module that you load up using Add-PSSnapin Microsoft.SharePoint.Powershell. You then write something like Get-SPSite -Identity http://localhost The Microsoft Scripting Guys have some good stuff on using them. – Mike H Jun 3 '11 at 1:15
  • aha, just found that add in. very helpful, thank you. – Daniel Williams Jun 3 '11 at 1:24

If you want to get a good grasp not only of Powershell for SharePoint, but of the basics of powershell as well, i suggest you get this book: PowerShell for Microsoft SharePoint 2010 Administrators. It offers excellent examples and step by step explanation of how to work with sharepoint using Powershell.

Also, if you want to see some really hardcore Powershell for sharepoint, I suggest downloading SPAutoinstaller, which performs a complete sharepoint install and touches pretty much every admin ps concept there is for sharepoint.

| improve this answer | |
  • Thanks Colin, I was looking at books, and saw this one. Your endorsement is a positive. – Daniel Williams Jun 3 '11 at 2:13
  • Great book, I bought that one to help me out and its a great starting point but if you have been doing this awhile it's going ot be a bit basic. – MichaelF Jun 29 '11 at 20:00

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.