1

I have owner right of a teamsite. But I am no tenant administrator. I only want access with PowerShell to my own teamsite not to the whole farm. But I found this code below to logon to sharepoint-online with administrative-rights.

$username = "my email-address"
$password = "my password"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
Connect-SPOService -Url https://mydomain-admin.sharepoint.com -Credential $cred

Running the code leads to an error saying that I am not a tenant-administrator. Is it possible to connect to just the teamsite and not the whole farm?

Gr, Peter

3
  • replace the url with your team site url....you URL is tenant Admin url.
    – Waqas Sarwar MVP
    Jan 17, 2019 at 15:51
  • I did. But then I get the error: current site is not a tenant administration site
    – user78519
    Jan 17, 2019 at 15:53
  • that would be a no; first because you use would not have permissions over the cmdlet [-Identity]. Jan 17, 2019 at 15:59

2 Answers 2

1

You cannt use the Connect-SPOService rather use the PNP or use the below PowerShell CSOM.

#Import the required DLL
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
#OR
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

#Mysite URL
$site = 'https://tenant.sharepoint.com/sites/sitename'

#Admin User Principal Name
$admin = '[email protected]'

#Get Password as secure String
$password = Read-Host 'Enter Password' -AsSecureString

#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

$list = $context.Web.Lists.GetByTitle('PowerShell CSOM')
$context.Load($list)
$list.Description = "CSOM PowerShell - Did it!!!"
$list.Update()
$context.ExecuteQuery()
4
  • CSOM is no option ( I am not authorized) . Is it perhaps possible to logon with PNP and use code From the Microsoft.Online.SharePoint.PowerShell module?
    – user78519
    Jan 17, 2019 at 16:06
  • Pnp has more commands related to client side.i would recommend either go pnp or csom
    – Waqas Sarwar MVP
    Jan 17, 2019 at 16:14
  • I already use pnp. But I have code that uses the Microsoft.Online.SharePoint.PowerShel module. And I want to try this code.
    – user78519
    Jan 17, 2019 at 16:16
  • Spo commands always run under tenant admin rights so that is road block for you.
    – Waqas Sarwar MVP
    Jan 17, 2019 at 16:23
0

UPDATED: Realized its SPOService. You might want to make use of

Connect-PnPOnline

You can pass site collection in this

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

3
  • I did. But then I get the error: current site is not a tenant administration site
    – user78519
    Jan 17, 2019 at 15:56
  • I don't want to user connect-pnponline. I want to use the Microsoft.Online.SharePoint.PowerShell module
    – user78519
    Jan 17, 2019 at 16:01
  • Sorry, you will have to use CSOM
    – Rohit
    Jan 17, 2019 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.