Use documented NinjaOne custom field commands
Some checks failed
OfficeCom Sentinel Client / validate-client (push) Successful in 23s
OfficeCom Sentinel Client / build-client-windows (push) Failing after 18s

This commit is contained in:
OfficeCom Codex
2026-07-25 21:17:59 +02:00
parent 49b0e3025d
commit 7431c656d3
4 changed files with 68 additions and 46 deletions

View File

@@ -46,8 +46,13 @@ function Initialize-NinjaFieldWriter {
return
}
if (Get-Command -Name "Set-NinjaProperty" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell-modern"
return
}
if (Get-Command -Name "Ninja-Property-Set" -ErrorAction SilentlyContinue) {
$script:NinjaFieldBackend = "powershell"
$script:NinjaFieldBackend = "powershell-legacy"
return
}
@@ -64,14 +69,20 @@ function Set-NinjaCustomFieldValue {
[Parameter(Mandatory)]
[string]$Name,
[AllowEmptyString()]
[string]$Value
[object]$Value,
[Parameter(Mandatory)]
[string]$Type
)
Initialize-NinjaFieldWriter
switch ($script:NinjaFieldBackend) {
"powershell" {
Ninja-Property-Set $Name $Value | Out-Null
"powershell-modern" {
Set-NinjaProperty -Name $Name -Value $Value -Type $Type -Force | Out-Null
return $true
}
"powershell-legacy" {
Ninja-Property-Set -Name $Name -Value $Value | Out-Null
return $true
}
"cli" {
@@ -112,28 +123,28 @@ function Publish-NinjaCustomFields {
}
}
$fieldValues = [ordered]@{
"ocsentinelstatus" = [string]$Report.AlertState
"ocsentinelreason" = $Reason
"ocsentinelbasestatus" = [string]$Report.BaseAlertState
"ocsentinelevents" = [string]([int]$Report.TotalEvents)
"ocsentineluniqueips" = [string]([int]$Report.UniqueIpCount)
"ocsentinelcvecritical" = [string]([int]$Report.VulnerabilityCorrelation.CriticalCount)
"ocsentinelcvetotal" = [string]([int]$Report.VulnerabilityCorrelation.TotalCount)
"ocsentinelmode" = $Mode
"ocsentineltriggered" = $Triggered.ToString().ToLowerInvariant()
"ocsentinellastscanutc" = $generatedAtUtc
}
$fieldValues = @(
[pscustomobject]@{ Name = "ocsentinelstatus"; Type = "Text"; Value = [string]$Report.AlertState }
[pscustomobject]@{ Name = "ocsentinelreason"; Type = "Text"; Value = $Reason }
[pscustomobject]@{ Name = "ocsentinelbasestatus"; Type = "Text"; Value = [string]$Report.BaseAlertState }
[pscustomobject]@{ Name = "ocsentinelevents"; Type = "Integer"; Value = [int]$Report.TotalEvents }
[pscustomobject]@{ Name = "ocsentineluniqueips"; Type = "Integer"; Value = [int]$Report.UniqueIpCount }
[pscustomobject]@{ Name = "ocsentinelcvecritical"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.CriticalCount }
[pscustomobject]@{ Name = "ocsentinelcvetotal"; Type = "Integer"; Value = [int]$Report.VulnerabilityCorrelation.TotalCount }
[pscustomobject]@{ Name = "ocsentinelmode"; Type = "Text"; Value = $Mode }
[pscustomobject]@{ Name = "ocsentineltriggered"; Type = "Checkbox"; Value = $Triggered }
[pscustomobject]@{ Name = "ocsentinellastscanutc"; Type = "DateTime"; Value = $generatedAtUtc }
)
$updated = 0
foreach ($entry in $fieldValues.GetEnumerator()) {
foreach ($entry in $fieldValues) {
try {
if (Set-NinjaCustomFieldValue -Name $entry.Key -Value $entry.Value) {
if (Set-NinjaCustomFieldValue -Name $entry.Name -Value $entry.Value -Type $entry.Type) {
$updated++
}
}
catch {
Write-Warning "Failed to set Ninja custom field '$($entry.Key)': $($_.Exception.Message)"
Write-Warning "Failed to set Ninja custom field '$($entry.Name)': $($_.Exception.Message)"
}
}