This post explains how to extend a Client ID / Client Secret pair using PowerShell. Examples of protected resources are SharePoint and Microsoft Graph.

Introduction

By default, a Client ID / Client Secret pair is only valid for 1 year. This post explains how to extend a client/secret using PowerShell, without the need for you to create a new Client ID / Client Secret pair.

The Code

#Application ID
$ClientID =  "" #Place your Client Id Here
$ClientSecret = "" #Place your Client Secret Here

#Connect to AzureAD
Connect-AzureAD

#Get the Client ID
$App = Get-AzureADServicePrincipal -All $true | Where-Object { $_.AppID -eq $ClientID }

#Get the Current Expiry Date
$CurrentExpiryDate = (Get-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId).EndDate
Write-Host "Current Expiry Date: "$CurrentExpiryDate -BackgroundColor Green

#Extend the validity of the App by 1 year
$StartDate = Get-Date
$EndDate = $StartDate.AddYears(1)
New-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId -StartDate $StartDate -EndDate $EndDate -Value $ClientSecret
New-AzureADServicePrincipalKeyCredential -ObjectId $App.ObjectId -StartDate $StartDate -EndDate $EndDate -Value $ClientSecret
$NewExpiryDate = (Get-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId).EndDate
Write-Host "New Expiry Date: "$NewExpiryDate -BackgroundColor Green

Related Articles

To learn why your business should migrate to SharePoint Online and Office 365, click here and here.

If you want to learn how to develop SPFx solutions, click here.

If you want to learn how you can rename a modern SharePoint site, click here.

If you want to learn how to save time time scheduling your meetings, click here.

If you want to learn how to enable Microsoft Teams Attendance List Download, click here.

If you want to learn how to create a dynamic org-wide team in Microsoft Teams with all active employees, click here.

If you want to modernize your SharePoint classic root site to a modern SharePoint site, click here.

If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint 2019 farm in an automated way using PowerShell, I invite you to click here and here.

If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click here.

If you prefer to use the traditional method to update your farm and want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated, click here.

If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click here and here.

If SharePoint 2019 is still not an option, you can learn more about how to install a SharePoint 2016 farm in an automated way using PowerShell, click here and here.

If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click here and here.

If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these learning resources.

If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read this article.

If you want to know all about the latest SharePoint and Office 365 announcements from Ignite and some more recent announcements, including Microsoft Search, What’s New to Build a Modern Intranet with SharePoint in Office 365, Deeper Integration between Microsoft Teams and SharePoint and the latest news on SharePoint development, click here.

If your organization is still not ready to go all in to SharePoint Online and Office 365, a hybrid scenario may be the best choice. SharePoint 2019 RTM was recently announced and if you to learn all about SharePoint 2019 and all its features, click here.

Happy SharePointing!

LEAVE A REPLY

Please enter your comment!
Please enter your name here