Skip to content

Commit

Permalink
add bpafield command
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Dec 8, 2023
1 parent 77f3019 commit 65f1673
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ function Add-CIPPAzDataTableEntity {
foreach ($SingleEnt in $Entity) {
try {
Add-AzDataTableEntity -context $Context -force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $SingleEnt
}
catch [System.Exception] {
if ($_.Exception.ErrorCode -eq "PropertyValueTooLarge" -or $_.Exception.ErrorCode -eq "EntityTooLarge") {
} catch [System.Exception] {
if ($_.Exception.ErrorCode -eq 'PropertyValueTooLarge' -or $_.Exception.ErrorCode -eq 'EntityTooLarge') {
try {
$MaxSize = 30kb
$largePropertyName = $null
Expand All @@ -36,10 +35,10 @@ function Add-CIPPAzDataTableEntity {
}

$splitInfo = @{
OriginalHeader = $largePropertyName;
OriginalHeader = $largePropertyName
SplitHeaders = $splitPropertyNames
}
$SingleEnt["SplitOverProps"] = ($splitInfo | ConvertTo-Json).ToString()
$SingleEnt['SplitOverProps'] = ($splitInfo | ConvertTo-Json).ToString()
$SingleEnt.Remove($largePropertyName)

for ($i = 0; $i -lt $splitData.Count; $i++) {
Expand All @@ -49,12 +48,10 @@ function Add-CIPPAzDataTableEntity {
Add-AzDataTableEntity -context $Context -force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $SingleEnt
}

}
catch {
} catch {
throw "Error processing entity: $($_.Exception.Message)."
}
}
else {
} else {
throw $_
}
}
Expand Down
46 changes: 46 additions & 0 deletions Modules/CIPPCore/Public/Add-CIPPBPAField.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Add-CIPPBPAField {
param (
$BPAName = 'Standards Report V1.0',
$FieldName,
$FieldValue,
$StoreAs,
$Tenant
)
$Table = Get-CippTable -tablename 'cachebpav2'
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant

$CurrentContentsObject = (Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq 'Standards Report V1.0' and PartitionKey eq '$($TenantName.customerId)'")
Write-Host "Adding $FieldName to $BPAName for $Tenant. content is $($CurrentContents.RowKey)"
if ($CurrentContentsObject.RowKey) {
$CurrentContents = @{}
$CurrentContentsObject.PSObject.Properties | ForEach-Object {
$CurrentContents[$_.Name] = $_.Value
}
$Result = $CurrentContents
} else {
$Result = @{
Tenant = "$($TenantName.displayName)"
GUID = "$($TenantName.customerId)"
RowKey = 'Standards Report V1.0'
PartitionKey = "$($TenantName.customerId)"
LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z')
}
}
switch -Wildcard ($StoreAs) {
'*bool' {
$Result["$fieldName"] = [bool]$FieldValue
}
'JSON' {

if ($FieldValue -eq $null) { $JsonString = '{}' } else { $JsonString = (ConvertTo-Json -Depth 15 -InputObject $FieldValue -Compress) }
$Result[$fieldName] = [string]$JsonString
}
'string' {
$Result[$fieldName], [string]$FieldValue
}
'percentage' {

}
}
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
}

0 comments on commit 65f1673

Please sign in to comment.