2

I am new in using powershell, I have been trying to solve this problem for hours and I cant still make it work.

Prerequisites:

  • Using windows 10
  • Running the Powershell ISE as Administrator

But when I used the "Add-PSSnapin WebAdministration"

Command that I am trying to run:

Add-PSSnapin Microsoft.Sharepoint.Powershell
$siteURL = Get-SPOSite "site"
$sitelists = foreach ($web in $siteURL.AllWebs) {
foreach($list in $web.lists){ $list } }
$sitelists |select * | Export-CSV C:\liststitles.csv

It shows the following error:

PS C:\windows\system32> Add-PSSnapin Microsoft.Sharepoint.Powershell
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.Sharepoint.Powershell' is not installed on this computer.
At line:1 char:1
+ Add-PSSnapin Microsoft.Sharepoint.Powershell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Sharepoint.Powershell:String) [Add-PSSnapin], PSArgumentEx 
   ception
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

I also downloaded the "iis7psprov_x64.msi", but I don't know how to install it since I cant run it as administrator. and also I have read that, it should be available in the "WebAdminstration" module. When trying to run the file the following error is prompted:

enter image description here

Might be simmlar to this but for windows 10:

Add-PsSnapin WebAdministration in Windows7

Community
  • 1
  • 1
SCS
  • 1,162
  • 3
  • 17
  • 31
  • The title for this question references `Microsoft.SharePoint.Powershell`. Your code example says `Add-PSSnapin WebAdministration`, with your error message referencing SharePoint again. Please can you clarify what you're trying to do? What commands do you need to run? SharePoint related commands are not part of the WebAdministration module (as far as I know). – Robin May 16 '17 at 09:44
  • @Robin sharepoint reletated command...sorry for the confusion. While searching for the answer I stumbled upon the WebAdministration module so I thought that's the error – SCS May 16 '17 at 09:48
  • 1
    WebAdministration is for Microsoft IIS. Are you trying to work with SharePoint in Office 365? Or locally? – Robin May 16 '17 at 09:52
  • @Robin for SharePoint office 365, edited the question with the code I am trying to run. Thanks – SCS May 16 '17 at 10:00
  • This is a good question, but please remove your references to "Add-PSSnapin WebAdministration" – Shawn Eary Mar 12 '21 at 16:44

1 Answers1

5

To work with SharePoint online, you need the SharePoint Online Management Shell PowerShell module. Once installed (on your Windows 10 machine), PowerShell will automatically load the commands you need (like Get-SPOSite) without needing to import the module manually.

You can download it from the link above, and an introduction is here: https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/introduction-sharepoint-online-management-shell?view=sharepoint-ps&redirectedfrom=MSDN

Robin
  • 1,602
  • 3
  • 16
  • 24
  • 3
    I have downloaded shrarepoint online management shell and also tried to used it as administrator, same error also – SCS May 16 '17 at 10:03
  • I don't really know what you mean by "no problem with connecting to sharepoint" but if you're connecting to SharePoint using `Connect-SPOService` then the commands are loaded. I can't see any reason why you need to run as 'Administrator'. It works for me and colleagues on Windows 10 both in PowerShell, PowerShell ISE and Visual Studio Code. Sorry I can't be of more help. – Robin May 16 '17 at 10:45
  • 1
    the `Connect-SPOService ` works, but for some reason the addspain does not work. thanks btw – SCS May 16 '17 at 11:28
  • 1
    It's a module, not a snapin so you don't need that line in your script. If the SharePoint online module has helped you access the commands required, then please mark this as the correct answer. Thank you. – Robin May 16 '17 at 11:51
  • i am trying to access and do something with my sharepoint site and without that code (from research) i dont think it will work. Thanks anyway – SCS May 16 '17 at 15:16
  • I have installed the SPO Managment shell on both Windows Server 2012R2 and Windows 10 20H2 and Connect-SPOService works for me, but I can't get "Add-PSSnapin microsoft.sharepoint.powershell" or "Enable-SPFeature ..." to work... – Shawn Eary Mar 12 '21 at 16:58
  • 1
    @ShawnEary The module referenced above is designed for SharePoint Online. As far as I can tell the cmdlet `Enable-SPFeature` seems to be part of a different module called SharePointServer: https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/enable-spfeature?view=sharepoint-ps. Snapins aren't a thing these days - it's all modules. – Robin Mar 16 '21 at 14:01