sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Not able to get expiry date using powershell script

Open rajendrasingh2121 opened this issue 8 years ago • 5 comments

$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.

rajendrasingh2121 avatar Sep 27 '18 20:09 rajendrasingh2121

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

}

paulewert avatar Oct 25 '18 15:10 paulewert

Hi @rajendrasingh2121 , Could you please provide a sample scenario? How did you occur this issue?

jxnx888 avatar Oct 29 '18 01:10 jxnx888

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.

rajendrasingh2121 avatar Oct 31 '18 10:10 rajendrasingh2121

Documentation updated based on PR from @paulewert in #2826. Thanks, everyone for your contribution.

VesaJuvonen avatar Nov 15 '18 08:11 VesaJuvonen

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

msft-github-bot avatar Jan 26 '20 12:01 msft-github-bot