Not able to get expiry date using powershell script
$date = get-date it return the current date of system not the expiry date in the Find out the expiration dates of the SharePoint Add-ins installed to the Office 365 tenancy section
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 3d9d8235-c495-a7a3-a4a6-0d073db41d1d
- Version Independent ID: bdd22da6-06c6-569d-fccf-fd55baa3cef8
- Content: Replace an expiring client secret in a SharePoint Add-in
- Content Source: docs/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in.md
- Product: sharepoint
- GitHub Login: @spdevdocs
- Microsoft Alias: spdevdocs
I use the following to get the start date and end (expiration) date of the app secrets. The code above should be corrected.
$applist = Get-MsolServicePrincipal -all |Where-Object -FilterScript { ($.DisplayName -notlike "Microsoft") -and ($.DisplayName -notlike "autohost*") -and ($_.ServicePrincipalNames -notlike "localhost") }
foreach ($appentry in $applist) { $principalId = $appentry.AppPrincipalId $principalName = $appentry.DisplayName
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | ? { $_.Type -eq "Password" } | % { "$principalName;$principalId;" + $_.KeyId.ToString() +";" + $_.StartDate.ToString() + ";" + $_.EndDate.ToString() } | out-file -FilePath c:\temp\appsec.txt -append
}
Hi @rajendrasingh2121 , Could you please provide a sample scenario? How did you occur this issue?
I ran below command in
$applist = Get-MsolServicePrincipal -all |Where-Object -FilterScript { ($.DisplayName -notlike "Microsoft") -and ($.DisplayName -notlike "autohost*") -and ($_.ServicePrincipalNames -notlike "localhost") }
foreach ($appentry in $applist) { $principalId = $appentry.AppPrincipalId $principalName = $appentry.DisplayName
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | Where-Object { ($.Type -ne "Other") -and ($.Type -ne "Asymmetric") }
$date = get-date Write-Host "$principalName;$principalId;$appentry.KeyId;$appentry.type;$date;$appentry.Usage"
} > c:\temp\appsec.txt
here you can see $date = get-date will always return the same date. https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in#find-out-the-expiration-dates-of-the-sharepoint-add-ins-installed-to-the-office-365-tenancy
So it would be great if anyone can update the powershell command to get the expiration of the secret.
Documentation updated based on PR from @paulewert in #2826. Thanks, everyone for your contribution.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues