Skip to content

Instantly share code, notes, and snippets.

@ryanshripat
Last active September 27, 2017 11:48
Show Gist options
  • Save ryanshripat/ca9686da385c3ad62a8495e669311cb1 to your computer and use it in GitHub Desktop.
Save ryanshripat/ca9686da385c3ad62a8495e669311cb1 to your computer and use it in GitHub Desktop.
This script lists the expiry dates of apps sideloaded onto an O365 SharePoint site, given the app name. Modified based on a script from https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in to accept the name of a particular app and formatted a little more clearly.
#This script lists the expiry dates of apps sideloaded onto an O365 SharePoint site, given the app name.
#Modified based on a script from https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in
#to accept the name of a particular app and formatted a little more clearly. Prerequisites for running this app are listed at the link above.
Clear-Host
Connect-MsolService
$appName = Read-Host 'Partial name of your app?'
$applist = Get-MsolServicePrincipal -all |Where-Object -FilterScript { ($_.DisplayName -like "*$appName*") -and ($_.DisplayName -notlike "*Microsoft*") -and ($_.DisplayName -notlike "autohost*") -and ($_.ServicePrincipalNames -notlike "*localhost*") }
foreach ($appentry in $applist)
{
$principalId = $appentry.AppPrincipalId
$principalName = $appentry.DisplayName
$date = get-date
Write-Host "$principalName`n($principalId;$appentry.KeyId;$appentry.type;$date;$appentry.Usage)"
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | Where-Object { ($_.Type -ne "Other") -and ($_.Type -ne "Asymmetric") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment