@@ -17,21 +17,22 @@ Function Invoke-ExecExtensionsConfig {
1717 # Connect-AzAccount -UseDeviceAuthentication
1818 # Write to the Azure Functions log stream.
1919 Write-Information ' PowerShell HTTP trigger function processed a request.'
20+ $Body = [PSCustomObject ]$Request.Body
2021 $results = try {
21- if ($Request . Body.CIPPAPI.Enabled ) {
22+ if ($Body.CIPPAPI.Enabled ) {
2223 try {
23- $APIConfig = New-CIPPAPIConfig - ExecutingUser $Request.Headers .' x-ms-client-principal' - resetpassword $Request . Body.CIPPAPI.ResetPassword
24+ $APIConfig = New-CIPPAPIConfig - ExecutingUser $Request.Headers .' x-ms-client-principal' - resetpassword $Body.CIPPAPI.ResetPassword
2425 $AddedText = $APIConfig.Results
2526 } catch {
2627 $AddedText = ' Could not enable CIPP-API. Check the CIPP documentation for API requirements.'
27- $Request . Body = $Request . Body | Select-Object * - ExcludeProperty CIPPAPI
28+ $Body = $Body | Select-Object * - ExcludeProperty CIPPAPI
2829 }
2930 }
3031
3132 # Check if NinjaOne URL is set correctly and the instance has at least version 5.6
32- if ($Request . Body.NinjaOne ) {
33+ if ($Body.NinjaOne ) {
3334 try {
34- [version ]$Version = (Invoke-WebRequest - Method GET - Uri " https://$ ( ($Request . Body.NinjaOne.Instance -replace ' /ws' , ' ' ) -replace ' https://' , ' ' ) /app-version.txt" - ea stop).content
35+ [version ]$Version = (Invoke-WebRequest - Method GET - Uri " https://$ ( ($Body.NinjaOne.Instance -replace ' /ws' , ' ' ) -replace ' https://' , ' ' ) /app-version.txt" - ea stop).content
3536 } catch {
3637 throw " Failed to connect to NinjaOne check your Instance is set correctly eg 'app.ninjarmmm.com'"
3738 }
@@ -41,39 +42,39 @@ Function Invoke-ExecExtensionsConfig {
4142 }
4243
4344 $Table = Get-CIPPTable - TableName Extensionsconfig
44- foreach ($APIKey in ([ pscustomobject ] $Request . Body).psobject.properties.name ) {
45+ foreach ($APIKey in $ Body.PSObject.Properties.Name ) {
4546 Write-Information " Working on $apikey "
46- if ($Request . Body .$APIKey.APIKey -eq ' SentToKeyVault' -or $Request . Body .$APIKey.APIKey -eq ' ' ) {
47+ if ($Body .$APIKey.APIKey -eq ' SentToKeyVault' -or $Body .$APIKey.APIKey -eq ' ' ) {
4748 Write-Information ' Not sending to keyvault. Key previously set or left blank.'
4849 } else {
4950 Write-Information ' writing API Key to keyvault, and clearing.'
5051 Write-Information " $ENV: WEBSITE_DEPLOYMENT_ID "
51- if ($Request . Body .$APIKey.APIKey ) {
52+ if ($Body .$APIKey.APIKey ) {
5253 if ($env: AzureWebJobsStorage -eq ' UseDevelopmentStorage=true' ) {
5354 $DevSecretsTable = Get-CIPPTable - tablename ' DevSecrets'
5455 $Secret = [PSCustomObject ]@ {
5556 ' PartitionKey' = $APIKey
5657 ' RowKey' = $APIKey
57- ' APIKey' = $Request . Body .$APIKey.APIKey
58+ ' APIKey' = $Body .$APIKey.APIKey
5859 }
5960 Add-CIPPAzDataTableEntity @DevSecretsTable - Entity $Secret - Force
6061 } else {
61- $null = Set-AzKeyVaultSecret - VaultName $ENV: WEBSITE_DEPLOYMENT_ID - Name $APIKey - SecretValue (ConvertTo-SecureString - AsPlainText - Force - String $Request . Body .$APIKey.APIKey )
62+ $null = Set-AzKeyVaultSecret - VaultName $ENV: WEBSITE_DEPLOYMENT_ID - Name $APIKey - SecretValue (ConvertTo-SecureString - AsPlainText - Force - String $Body .$APIKey.APIKey )
6263 }
6364 }
64- if ($Request . Body .$APIKey.PSObject.Properties -notcontains ' APIKey' ) {
65- $Request . Body .$APIKey | Add-Member - MemberType NoteProperty - Name APIKey - Value ' SentToKeyVault'
65+ if ($Body .$APIKey.PSObject.Properties.Name -notcontains ' APIKey' ) {
66+ $Body .$APIKey | Add-Member - MemberType NoteProperty - Name APIKey - Value ' SentToKeyVault'
6667 } else {
67- $Request . Body .$APIKey.APIKey = ' SentToKeyVault'
68+ $Body .$APIKey.APIKey = ' SentToKeyVault'
6869 }
6970 }
70- $Request . Body .$APIKey = $Request . Body .$APIKey | Select-Object * - ExcludeProperty ResetPassword
71+ $Body .$APIKey = $Body .$APIKey | Select-Object * - ExcludeProperty ResetPassword
7172 }
72- $body = $Request . Body | Select-Object * - ExcludeProperty APIKey, Enabled | ConvertTo-Json - Depth 10 - Compress
73+ $Body = $Body | Select-Object * - ExcludeProperty APIKey, Enabled | ConvertTo-Json - Depth 10 - Compress
7374 $Config = @ {
7475 ' PartitionKey' = ' CippExtensions'
7576 ' RowKey' = ' Config'
76- ' config' = [string ]$body
77+ ' config' = [string ]$Body
7778 }
7879
7980 Add-CIPPAzDataTableEntity @Table - Entity $Config - Force | Out-Null
0 commit comments