Skip to main content -->

Connect to SharePoint

Connecting to a SharePoint site is fairly straightforward. Use the Connect-SPOWeb command to do so.

SharePoint connections are managed on a per-web-site basis. So, if you have multiple sub-sites you want to connect to, you will need to connect multiple times.

CloudPower keeps track of the sites you've connected to and can re-use credentials for sub-webs that are in the same site collection.

New for 11/28/2016, we now save the Password to the Windows Credential Manager so that you don't have to enter it on subsequent connections. Of course, if you don't want this, it can be disabled.

Connect-SPOWeb Example

In order to make integrating with other solutions as easy as possible, we provided three ways to connect to a SharePoint web site:

  • Web+User+Pass: Provide a SharePoint URL, a User Name, and a secure Password.
  • Web+Credentials: Provide a SharePoint URL, and a System.Security.Credential object.
  • Client Context: Provide a SharePoint client context (Microsoft.SharePoint.Client.ClientContext).
   
$url = https://liquidhgdemo.sharepoint.com/sites/cpdemo1
$user = testuser@liquidhgdemo.onmicrosoft.com
$pw = ConvertTo-SecureString -String MyPassword123 -AsPlainText -Force
Connect-SPOWeb -TargetWeb $url -UserName $user -Password $pw

or...

   
#Create a context outside of CloudPower and import it so you can run CP commands.
#You can also implement other custom methods for getting your credentials and context.
Function Get-SPOCredentials([string]$UserName,[string]$Password) {
  $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
Connect-SPOWeb -Context $context

or...


$cred = Get-Credential # prompts for login
Connect-SPOWeb -TargetWeb $url -Credential $cred

Connect-SPOWeb Parameters

  • -TargetWeb: The URL for your SharePoint site. Remember, if you want the connection to be secure, you should use HTTPS. While all Office 365 SharePoint sites use HTTPS, not all on premises sites do, so check with your system admin to make sure HTTP connections are OK and safe to use.
  • -UserName: Your Windows or Office 365 user name depending on whether you're connecting to SharePoint or SharePoint Online.
  • -Password: A secure string with your password. Use Convert-ToSecureString command to generate one, or leave this parameter out and CloudPower will prompt you.
  • -Credential: A combination similar to passing in -UserName and -Password.
  • -Context: In leiu of -TargetWeb, -UserName. and -Password, you can provide a ClientContext object from other CSOM operations. This is useful for integrating with custom code and other solutions, but note that automatic reconnection is not supported in this scenario, and it will operate in a manner similar to using the -DisableCredentialCaching parameter.
  • -AuthType: Determines the authentication scheme that will be used to connect. Note that SPOCredential is the default, so if you're using SharePoint Online you do not need to specify this parameter at all. Possible values include:
    • SharePointClaims: A SharePoint site using claims authentication. Note that in many configurations, using this setting may require the user to login using a web page.
    • SharePointForms: A SharePoint site using FBA. Note that in many configurations, using this setting may require the user to login using a web page.
    • SharePointNTLMCurrentUser: Pass the credentials of the current Windows user signed into the PC. This setting will cause -UserName and -Password parameters to be ignored.
    • SharePointNTLMUserPass: Provide Windows login credentials using the -UserName and -Password parameters. In this case -UserName should follow the format DOMAIN\username.
    • SPOCredentials: This is the default and uses the standard, modern methodology for connecting CSOM to SharePoint Online sites.
    • SPOCustomCookie: Gets a SharePoint Online credential using a custom implementation that was developed before SPOCredentials existed. While this may have its uses, it is mostly kept around out of a feeling of nostalgia. Most Office 365 users should want to use SPOCredentials instead.
    • Unknown: The authentication method is unspecified, and the connection will try to figure out the appropriate authentication scheme based on known values like the -TargetWeb url or the presence and format of -UserName.
  • -GetContextManagerFromCache: add this when you wnat to recycle the connection as it already exists from a previous Connect-SPOWeb command.
  • -DisableCredentialManager: By default, CloudPower will save your login information to the Windows Credential Manager on your local machine. This switch will disable the reading and writing of credentials, such as when you're using a shared computer.
  • -DisableCredentialCaching: By default, SharePoint credentials are stored in the connection manager. This was done to allow automatic reconnection if SharePoint occassionally times out or throws 401 errors in the middle of a long running operation. You may turn this off it you would rather have CloudPower commands throw an error in such cases instead.

Optional License Parameters

Provide these if you are running CloudPower for the first time and do not want to be prompted to manaually enter product registration information. They are optional, and work as a set. As an alternative you may run the Register-CloudPower and/or Get-CloudPowerRegistration commands before connecting in order to ensure that a valid product serial number exists.

  • -Email: This is the email you want to register CloudPower with, and can be different than your Office 365 or SharePoint login provided in the -UserName parameter. It is only used when you provide other paramters for product registration below. If you leave it out, the -UserName may be used instead, or you may be prompted for enter it manually.
  • -SerialOrLicenseCode: If you've already purchased CloudPower, you can provide a license key so you won't be prompted for it. This is the same as choose option 1/K from the product registration menu. When using -SerialOrLicenseCode only -Email is required.
  • -VoucherCpde: If you were given a free gift voucher code, use this parameter to redeem it for your product code. You must provide -FirstName, -LastName, -Company, and -ClientDomains or you will be prompted to enter them manually. This will cash in the code and tie it to you personally, so be sure to write down the information returned to you.
  • -FirstName: Used when registering the free edition of CloudPower. You must provide -FirstName, -LastName, -Company, and -ClientDomains or you will be prompted to enter them manually.
  • -LastName: Used when registering the free edition of CloudPower. You must provide -FirstName, -LastName, -Company, and -ClientDomains or you will be prompted to enter them manually.
  • -Company: Used when registering the free edition of CloudPower. You must provide -FirstName, -LastName, -Company, and -ClientDomains or you will be prompted to enter them manually.
  • -ClientDomains: An array of the SharePoint DNS domains you want to register for use. Used when registering the free edition of CloudPower. You must provide -FirstName, -LastName, -Company, and -ClientDomains or you will be prompted to enter them manually.
  • -TestMode: This parameter is for our developers to test product registration features against our lab environment and should not be used.