Özel Çözüm: REST API ile Endpoint Central Envanter Tarama Sıklığını Kısaltma

AI Ön İzleme

Bu içerik sana uygun mu? Kısa ön izleme ile hızlıca karar ver.

Techaptic’e hoş geldiniz!

Bugünkü rehberimizde, ManageEngine Endpoint Central üzerinde envanter taramalarını, sistemin günde bir kez olan varsayılan kısıtlamasını aşarak nasıl daha sık yapabileceğinizi gösteriyoruz.

Endpoint Central’da zamanlanmış envanter taramaları en fazla günde bir defa çalışacak şekilde sınırlandırılmıştır ve bu durum güncel bilgiye ihtiyaç duyan ortamlar için yetersiz kalabilir. Bu yazımızda, Endpoint Central’ın mevcut zamanlama ayarlarını değiştirmeden REST API altyapısı, PowerShell ve Windows Görev Zamanlayıcısı kullanarak envanter taramalarını istediğiniz aralıklarla nasıl tetikleyebileceğinizi anlatıyoruz. Ayrıca, API kimlik doğrulama token’ını Windows DPAPI mekanizmasıyla şifreleyerek güvenliği en üst düzeyde tutuyoruz. Uç noktalarınızda güncel görünürlüğü güvenli bir şekilde sağlamak için bu özel çözümü adım adım uygulayabilirsiniz.

🔗 Faydalı Linkler
  • Bu bölümde paylaşılan bir link bulunmamaktadır.

Video Anlatımı

Kullanılan Komutlar


Güvenli API token depolama betiği (Save-EcAuthTokenMachine.ps1)

<#
.SYNOPSIS
Techaptic - Endpoint Central Secure API Token Storage Script

.DESCRIPTION
Protects the Endpoint Central API authentication token by using
Windows DPAPI with the LocalMachine scope.

The encrypted token is stored as Base64 data, and the token file
permissions are restricted to SYSTEM and Administrators.

.NOTES
Author: Techaptic

The script must be run from an elevated PowerShell session.

Default Output:
C:\ProgramData\EPC\ec_authtoken.machine
#>

# C:\Scripts\Save-EcAuthTokenMachine.ps1
# Encrypts the token with DPAPI LocalMachine.

[CmdletBinding()]
param(
[Parameter()]
[string]$OutputPath = "$env:ProgramData\EPC\ec_authtoken.machine",

[Parameter()]
[string]$EntropyText = "EPC_TOKEN_V1_LOCALMACHINE"
)

function Ensure-Dir([string]$Path) {
$d = Split-Path -Parent $Path
if ($d -and !(Test-Path $d)) {
New-Item -ItemType Directory -Path $d -Force | Out-Null
}
}

function Get-Plain([Security.SecureString]$SecureString) {
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
try {
[Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
}
finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
}
}

Write-Host ""
Write-Host "Techaptic - Endpoint Central Secure API Token Configuration Initiated..." -ForegroundColor Cyan
Write-Host "------------------------------------------------------------------------" -ForegroundColor Cyan

Write-Host "Processing: Token directory preparation... " -NoNewline
Ensure-Dir $OutputPath
Write-Host "[SUCCESS]" -ForegroundColor Green

Write-Host "Paste Endpoint Central Authentication Token and hit Enter:" -ForegroundColor Yellow
$tokenSecure = Read-Host -AsSecureString
$plain = Get-Plain $tokenSecure

if ([string]::IsNullOrWhiteSpace($plain)) {
Write-Host "[ERROR] Token is empty. The process is cancelled." -ForegroundColor Red
throw "Token was entered empty. Process cancelled."
}

Write-Host "Processing: DPAPI LocalMachine encryption... " -NoNewline
Add-Type -AssemblyName System.Security

$bytes = [Text.Encoding]::UTF8.GetBytes($plain)
$entropy = [Text.Encoding]::UTF8.GetBytes($EntropyText)

$protected = [Security.Cryptography.ProtectedData]::Protect(
$bytes,
$entropy,
[Security.Cryptography.DataProtectionScope]::LocalMachine
)

$b64 = [Convert]::ToBase64String($protected)
Set-Content -Path $OutputPath -Value $b64 -Encoding ASCII -NoNewline
Write-Host "[SUCCESS]" -ForegroundColor Green

Write-Host "Processing: Token file ACL configuration... " -NoNewline
& icacls $OutputPath /inheritance:r | Out-Null
& icacls $OutputPath /grant:r "SYSTEM:(R)" "Administrators:(R)" | Out-Null
Write-Host "[SUCCESS] (SYSTEM and Administrators: Read)" -ForegroundColor Green

Write-Host "------------------------------------------------------------------------" -ForegroundColor Cyan
Write-Host "Process Completed. Authentication token stored securely." -ForegroundColor Green
Write-Host "Token File: $OutputPath" -ForegroundColor Green

Tam envanter taramasını tetikleyen betik (Invoke-EcInventoryScanAll.ps1)

<#
.SYNOPSIS
Techaptic - Endpoint Central Full Inventory Scan Trigger Script

.DESCRIPTION
Triggers a full inventory scan for all computers managed by
ManageEngine Endpoint Central.

The script reads the DPAPI-protected API token created by
Save-EcAuthTokenMachine.ps1 and sends an authenticated POST
request to the Endpoint Central Scan All API.

.NOTES
Author: Techaptic

API Endpoint:
POST /api/1.4/inventory/computers/scanall

Required API Permission:
Inventory - Update

Default Token File:
C:\ProgramData\EPC\ec_authtoken.machine

Default Log File:
C:\Windows\Temp\ec_inventory_scanall.log
#>

# C:\Scripts\Invoke-EcInventoryScanAll.ps1

[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$ServerBaseUrl,

[Parameter()]
[string]$TokenFile = "$env:ProgramData\EPC\ec_authtoken.machine",

[Parameter()]
[string]$EntropyText = "EPC_TOKEN_V1_LOCALMACHINE",

[Parameter()]
[string]$LogFile = "C:\Windows\Temp\ec_inventory_scanall.log",

[Parameter()]
[ValidateRange(5,300)]
[int]$TimeoutSec = 60
)

function Ensure-Dir([string]$Path) {
$d = Split-Path -Parent $Path
if ($d -and !(Test-Path $d)) {
New-Item -ItemType Directory -Path $d -Force | Out-Null
}
}

function Write-Log([string]$Msg, [ValidateSet("INFO","WARN","ERROR")]$Level="INFO") {
Ensure-Dir $LogFile
$ts = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
Add-Content -Path $LogFile -Value "$ts | $Level | $Msg" -Encoding UTF8
}

function To-Json([object]$o) {
try {
return ($o | ConvertTo-Json -Depth 10 -Compress)
} catch {
return "<json_failed>"
}
}

function Get-AuthToken-FromLocalMachineFile([string]$Path, [string]$EntropyText) {
if (!(Test-Path $Path)) { throw "Token file not found: $Path" }

$b64 = (Get-Content -Path $Path -Raw).Trim()

if ([string]::IsNullOrWhiteSpace($b64)) { throw "Token file is empty: $Path" }

Add-Type -AssemblyName System.Security
$protected = [Convert]::FromBase64String($b64)
$entropy = [Text.Encoding]::UTF8.GetBytes($EntropyText)

$bytes = [Security.Cryptography.ProtectedData]::Unprotect(
$protected,
$entropy,
[Security.Cryptography.DataProtectionScope]::LocalMachine
)

$plain = [Text.Encoding]::UTF8.GetString($bytes)

if ([string]::IsNullOrWhiteSpace($plain)) { throw "Token decrypted but returned empty." }

return $plain
}

Write-Host ""
Write-Host "Techaptic - Endpoint Central Full Inventory Scan Initiated..." -ForegroundColor Cyan
Write-Host "------------------------------------------------------------------" -ForegroundColor Cyan

try {
Write-Host "Processing: Endpoint Central server address... " -NoNewline
$ServerBaseUrl = $ServerBaseUrl.Trim().TrimEnd("/")
Write-Host "[SUCCESS] ($ServerBaseUrl)" -ForegroundColor Green

try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
} catch {}

Write-Host "Processing: Secure authentication token retrieval... " -NoNewline
$authToken = Get-AuthToken-FromLocalMachineFile -Path $TokenFile -EntropyText $EntropyText
Write-Host "[SUCCESS]" -ForegroundColor Green

$headers = @{
"Authorization" = $authToken
"Accept" = "application/json"
"Content-Type" = "application/json"
}

$url = "$ServerBaseUrl/api/1.4/inventory/computers/scanall"

Write-Host "Processing: Inventory Scan All API request... " -NoNewline
Write-Log "START | INVENTORY scanall -> POST $url"

$resp = Invoke-RestMethod -Method POST -Uri $url -Headers $headers -TimeoutSec $TimeoutSec -ErrorAction Stop

Write-Log "RESPONSE: $(To-Json $resp)"
Write-Log "DONE | Success"
Write-Host "[SUCCESS]" -ForegroundColor Green

Write-Host "------------------------------------------------------------------" -ForegroundColor Cyan
Write-Host "Process Completed. Full inventory scan request was accepted." -ForegroundColor Green
Write-Host "API Endpoint: $url" -ForegroundColor Green
Write-Host "Log File: $LogFile" -ForegroundColor Green

exit 0
}
catch {
Write-Host "[ERROR] ($($_.Exception.Message))" -ForegroundColor Red
Write-Log ("FATAL: " + $_.Exception.Message) "ERROR"

Write-Host "------------------------------------------------------------------" -ForegroundColor Cyan
Write-Host "Process Failed. Full inventory scan could not be triggered." -ForegroundColor Red
Write-Host "Log File: $LogFile" -ForegroundColor Yellow

exit 1
}

Mini Sınav


QUIZ-TR-Ozel-Cozum-REST-API-ile-Endpoint-Central-Envanter-Tarama-Sikligini-Kisaltma-5
  • Soru
  • Soru
  • Soru
  • Soru
  • Soru

Tam Transkript

Değerlendirme

Post Rating (TR)
Scroll to Top