0

When I try to run the command Add-PSSnapin Microsoft.SharePoint.Powershell in SharePoint Online Management Shell

I get the following error:

Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SharePoint.Powershell` is not installed on this computer

+ CategoryInfo: InvalidArgument: (Microsoft.SharePoint.Powershell:string) [Add-PSSnapin], PSArgumentException

From what I understand this is supposed to come installed with SharePoint Online Management Shell anyway (this is a fresh download) so why won't it let me install it

I can login to Sharepoint using the $AdminURL, $AdminName & $Password so it's not the end of the world (and proves that this should work), but obviously makes the script less easy to run across sites as it has to be modified everytime to change the url and adminname

EDIT: I read on another post that adding this module (not snapin) would fix my issue of the error Get-SPSite is not recognized as the name of a cmdlet, function, script file, or operable program and Get-SPWebApplication is not recognized as the name of a cmdlet, function, script file, or operable program However, this did not fix my problem...

blau
  • 73
  • 3
  • 13
  • 1
    Possible duplicate of [43997587](https://stackoverflow.com/questions/43997587/windows-powershell-snap-in-microsoft-sharepoint-powershell-is-not-installed-on). Are you able to run `Connect-SPOService`? According to the other thread, it's a module, not a snap-in so it doesn't need to be loaded as such. – kuzimoto May 14 '19 at 18:56
  • 1
    `Install-Module -Name Microsoft.Online.SharePoint.PowerShell` Powershell should be run in elevated mode (as administrator) As far as I remember microsoft decided to move away from snap-ins. Modules will be automatically imported, when you use any command from the module as long as module is located in one of the `$env:psmodulePath` paths. – 2 B May 14 '19 at 18:57
  • This worked, however did not solve my problem which I should have specified more clearly, editing the post now... – blau May 14 '19 at 19:02
  • 1
    @jblaupunkt try using `get-module -listavailable` look for the Sharepoint module and try `import-module ` or use get-command "Get-SPWebApplication" check what module it is in and import the module – 2 B May 14 '19 at 19:12
  • 1
    @jblaupunkt Are you trying to access an on-premisis SharePoint server, or online? Because the commands you're trying to use `Get-SPSite` and `Get-SPWebApplication` are designed to be used with [Sharepoint Server](https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-server/sharepoint-server-cmdlets?view=sharepoint-ps). – kuzimoto May 14 '19 at 19:13
  • online, I see the issue now is I should be using Connect-SPOService, right? – blau May 14 '19 at 19:15
  • 1
    @jblaupunkt Yes, that should do the trick. – kuzimoto May 14 '19 at 19:16

1 Answers1

0

As mentioned by user @kuzimoto the commands I was using were not compatible with SharePoint Online and were designed to be used in conjunction with SharePoint Server.

The correct way to connect is using the command Connect-SPOService and passing through the credentials through there or just have them hard coded into your script.

blau
  • 73
  • 3
  • 13