Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Simplifying Client Credentials with PowerShell: Add-ClientCredential
September 27
Simplifying Client Credentials with PowerShell: Add-ClientCredential

If you’ve been around the block with SharePoint or Microsoft 365 administration, you know that handling client credentials can sometimes feel like juggling with fire. When I start a new engagement with a client I generally get credentials to access their tenant. Of course they immediately go into our password management tool. I also do a lot of PowerShell scripting for my clients, so I save them to the Windows Credential store too, so that I can connect with Connect-PnPOnline without having to enter them each time. And while that’s not a lot of work, I thought I could streamline it. That’s why I’ve put together a PowerShell command, Add-ClientCredential, that makes it a little easier.

What Does Add-ClientCredential do?

In a nutshell, this PowerShell command is designed to streamline the process of adding client credentials in a SharePoint or Microsoft 365 environment. It stores your credential for https://tenant.sharepoint.com and https://tenant-admin.sharepoint.com. If you don’t specify any credentials when you connect with Connect-PnPOnline it will look for them in the Windows Credential Store. If you have one assigned for the root of the tenant, https://tenant.sharepoint.com, it will also use that for other sites in the tenant, like https://tenant.sharepoint.com/sites/ToddisTheBest, if a credential is not saved for that specific site.

Here’s a quick example:

Add-ClientCredential -TenantName "contoso" -UserName admin@contoso.com

I like this method because then my password will never show up in History or a Transcript if one is running. Since we didn’t pass it a password, it will prompt you for one. Then it will create credential entries for https://contoso.sharepoint.com, http://contoso.sharepoint.com, and https://contoso-admin.sharepoint.com

To pass it a password, do it like this:

Add-ClientCredential -TenantName "contoso" -UserName admin@contoso.com -Password (ConvertTo-SecureString "YourPassword”
-AsPlainText -Force)

Keep in mind that will show up in plain text in PowerShell’s Get-History, or the Transcript file, if you have that running.

I built in some smarts so that if there is already a credential stored for “Contoso” it will let you know and ask you if you want to overwrite it.

If you want to get super fancy you can add the –TestCredential switch which will test the credentials you gave it by logging in with them. All of this is available if you run help Add-ClientCredential –Examples.

In the background this function uses Add-PnPStoredCredential to store the credentials for you. It adds them for the root of the tenant, and the –admin URL.

How to Get Started

To get your hands on this little beauty, head over to my GitHub repository. You can download addclientcreds.psm1 itself, or clone the whole repo. Use Import-Module to import it into your PowerShell host and you’re ready to go.

Wrapping Up

addclientcreds.psm1 is my attempt to put a little more simplicity and sanity into the world of SharePoint and Microsoft 365 administration. I hope you find it as useful as I do. As always, I welcome your feedback and questions. Drop a comment below or shoot me a message on Twitter @ToddKlindt.

tk

ShortURL: https://www.toddklindt.com/PoshAddClientCreds

Comments

https://rhcchvac.com/

<a href="https://rhcchvac.com/">rhcc hvac</a>
<a href="https://rhcchvac.com/">rhcc hvac</a>
<a href="https://rhcchvac.com/">rhcc hvac</a>
<a href="https://rhcchvac.com/">rhcc hvac</a>
<a href="https://rhcchvac.com/">rhcc hvac</a>
 on 10/29/2024 10:20 AM

Re: Simplifying Client Credentials with PowerShell: Add-ClientCredential

<a href="https://www.google.com/">information</a>

[Thank you for the information](https://www.google.com)

[http://www.google.com test keyword]

[url=https://www.google.com]thanks for the info[/url]
 on 11/6/2024 5:26 AM

InstaCams

Yes, users can report any inappropriate behavior or violations of community guidelines to the InstaCams support team for review and action.

https://www.instacams.org/
 on 11/11/2024 10:11 AM

VideoChatopedia

Our guidelines also cover how to recognize and avoid potential scams or malicious behavior. By staying informed and cautious, you can enjoy a safer online experience and avoid common pitfalls. 🚫

https://www.videochatopedia.com/
 on 11/11/2024 10:12 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit