Modern BT altyapısında, sistemler artık birbirinden izole çalışmıyor. PowerShell’in Invoke-RestMethod komutu, AD, envanter sistemleri ve Jira gibi biletleme araçları arasında güçlü köprüler kurmanızı sağlar.
Temel REST API Çağrısı
$header = @{
"Authorization" = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("kullanici:api-token"))
"Content-Type" = "application/json"
}
$sonuc = Invoke-RestMethod -Uri "https://sirket.atlassian.net/rest/api/2/issue/PROJ-123" -Method Get -Headers $header
$sonuc.fields.summary
Örnek Senaryo: AD’den Jira’ya Otomatik Bilet Açma
Bir kullanıcının hesabı devre dışı bırakıldığında, ilgili BT ekibine otomatik bir Jira bileti açan bir entegrasyon kurmuştum:
function New-JiraBileti {
param($ozet, $aciklama)
$body = @{
fields = @{
project = @{ key = "ITOPS" }
summary = $ozet
description = $aciklama
issuetype = @{ name = "Task" }
}
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri "https://sirket.atlassian.net/rest/api/2/issue" `
-Method Post -Headers $header -Body $body
}
# Kullanım: bir AD hesabı devre dışı bırakıldığında
New-JiraBileti -ozet "Hesap devre dışı bırakıldı: jsmith" `
-aciklama "jsmith hesabı 90 gün inaktiflik nedeniyle otomatik devre dışı bırakıldı. Ekipman iadesi kontrol edilmeli."
Envanter Sistemine Veri Gönderme Örneği
PowerShell ile toplanan donanım envanterini merkezi bir envanter API’sine göndermek:
$envanter = Get-CimInstance Win32_ComputerSystem | Select-Object Manufacturer, Model
$disk = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object Size, FreeSpace
$payload = @{
hostname = $env:COMPUTERNAME
manufacturer = $envanter.Manufacturer
model = $envanter.Model
diskTotalGB = [math]::Round($disk.Size / 1GB, 2)
diskFreeGB = [math]::Round($disk.FreeSpace / 1GB, 2)
lastUpdated = (Get-Date -Format "o")
} | ConvertTo-Json
Invoke-RestMethod -Uri "https://envanter.sirket.com/api/cihazlar" -Method Post -Body $payload -ContentType "application/json"
Hata Yönetimi: API Çağrılarında Sağlamlık
try {
$sonuc = Invoke-RestMethod -Uri $apiUrl -Method Get -Headers $header -TimeoutSec 30
} catch {
if ($_.Exception.Response.StatusCode.value__ -eq 401) {
Write-Host "Kimlik doğrulama hatası - API token geçersiz olabilir" -ForegroundColor Red
} elseif ($_.Exception.Response.StatusCode.value__ -eq 429) {
Write-Host "Rate limit aşıldı - biraz bekleyip tekrar deneyin" -ForegroundColor Yellow
} else {
Write-Host "API hatası: $($_.Exception.Message)" -ForegroundColor Red
}
}
Sonuç
PowerShell’in REST API yetenekleri, AD’yi tek başına izole bir sistem olmaktan çıkarıp, biletleme, envanter ve daha fazlasıyla konuşan entegre bir BT ekosisteminin parçası haline getirir. Bu tür entegrasyonlar, manuel bilgi aktarımından kaynaklanan gecikmeleri ve hataları ortadan kaldırır.