|
1 |
| -### Example 1: {{ Add title here }} |
| 1 | +### Example 1: Add a password credential to an application with a six month expiry |
| 2 | + |
2 | 3 | ```powershell
|
3 |
| -PS C:\> {{ Add code here }} |
4 | 4 |
|
5 |
| -{{ Add output here }} |
| 5 | +Connect-MgGraph -Scopes 'Application.ReadWrite.All' |
| 6 | +
|
| 7 | +$appObjectId = 'eaf1e531-0d58-4874-babe-b9a9f436e6c3' |
| 8 | +
|
| 9 | +$passwordCred = @{ |
| 10 | + displayName = 'Created in PowerShell' |
| 11 | + endDateTime = (Get-Date).AddMonths(6) |
| 12 | +} |
| 13 | +
|
| 14 | +$secret = Add-MgApplicationPassword -applicationId $appObjectId -PasswordCredential $passwordCred |
| 15 | +$secret | Format-List |
| 16 | +
|
| 17 | +CustomKeyIdentifier : |
| 18 | +DisplayName : Created in PowerShell |
| 19 | +EndDateTime : 26/11/2022 12:03:31 pm |
| 20 | +Hint : Q_e |
| 21 | +KeyId : c82bb763-741b-4575-9d9d-df7e766f6999 |
| 22 | +SecretText : Q_e8Q~ZDWJD.bkgajbREp-VFFUayCuEk8b1hDcr9 |
| 23 | +StartDateTime : 26/5/2022 1:03:31 pm |
| 24 | +AdditionalProperties : {[@odata.context, |
| 25 | + https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential]} |
6 | 26 | ```
|
7 | 27 |
|
8 |
| -{{ Add description here }} |
| 28 | +Add a password to an application that expires in six months from the current date. |
| 29 | + |
| 30 | +### Example 2: Add a password credential to an application with a start date |
9 | 31 |
|
10 |
| -### Example 2: {{ Add title here }} |
11 | 32 | ```powershell
|
12 |
| -PS C:\> {{ Add code here }} |
13 | 33 |
|
14 |
| -{{ Add output here }} |
| 34 | +Connect-MgGraph -Scopes 'Application.ReadWrite.All' |
| 35 | +
|
| 36 | +$appObjectId = 'eaf1e531-0d58-4874-babe-b9a9f436e6c3' |
| 37 | +
|
| 38 | +$startDate = (Get-Date).AddDays(1).Date |
| 39 | +$endDate = $startDate.AddMonths(6) |
| 40 | +
|
| 41 | +$passwordCred = @{ |
| 42 | + displayName = 'Created in PowerShell' |
| 43 | + startDateTime = $startDate |
| 44 | + endDateTime = $endDate |
| 45 | +} |
| 46 | +
|
| 47 | +$secret = Add-MgApplicationPassword -applicationId $appObjectId -PasswordCredential $passwordCred |
| 48 | +$secret | Format-List |
| 49 | +
|
| 50 | +CustomKeyIdentifier : |
| 51 | +DisplayName : Created in PowerShell |
| 52 | +EndDateTime : 26/11/2022 1:00:00 pm |
| 53 | +Hint : TiA |
| 54 | +KeyId : 082bf20f-63d6-4970-bb4e-55e504f50d8b |
| 55 | +SecretText : TiA8Q~Zs7ej1cGtlW0qnmuFi~JlxXTZew_tU1bGA |
| 56 | +StartDateTime : 26/5/2022 2:00:00 pm |
| 57 | +AdditionalProperties : {[@odata.context, |
| 58 | + https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential]} |
15 | 59 | ```
|
16 | 60 |
|
17 |
| -{{ Add description here }} |
| 61 | +Add a password to an application that becomes valid at 12:00 am the next day and is valid for six months. |
18 | 62 |
|
| 63 | +Use `$secret.StartDateTime.ToLocalTime()` to convert the returned dates from UTC to the local timezone. |
0 commit comments