Skip to content

Commit cb94f8e

Browse files
Updated export of ServicePrincipalCredentials
Updated the PowerShell script for exporting ServicePrincipalCredentials more readable so it is clear to the reader what it is doing. Also used an object and exported it to CSV instead of a text file
1 parent 5e1b20d commit cb94f8e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ Ensure the following before you begin:
4848
4949
foreach ($appentry in $applist) {
5050
$principalId = $appentry.AppPrincipalId
51-
$principalName = $appentry.DisplayName
5251
53-
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
52+
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | Where-Object { $_.Type -eq "Password" } | ForEach-Object {
53+
[PSCustomObject][Ordered]@{
54+
PrincipalName = $appentry.DisplayName
55+
PrincipalId = $principalId
56+
KeyID = $_.KeyId
57+
StartDate = $_.StartDate
58+
EndDate = $_.EndDate
59+
} | Export-Csv -Path C:\temp\appsec.csv -NoTypeInformation -Delimiter ';' -Append
60+
}
5461
}
5562
```
5663
57-
1. Open the file C:\temp\appsec.txt to see the report. Leave the Windows PowerShell window open for the next procedure, if any of the secrets are near expiration.
64+
1. Open the file C:\temp\appsec.csv to see the report. Leave the Windows PowerShell window open for the next procedure, if any of the secrets are near expiration.
5865
5966
## Generate a new secret
6067

0 commit comments

Comments
 (0)