Backup
This commit is contained in:
parent
6c29ab88e8
commit
195d159fae
33
agent.ps1
33
agent.ps1
@ -28,16 +28,35 @@ foreach ($Path in $RegistryPaths) {
|
||||
# Unique list and sort
|
||||
$Software = $Software | Sort-Object Name -Unique
|
||||
|
||||
$Inventory = @{
|
||||
ComputerName = $ComputerName
|
||||
User = $User
|
||||
IPAddress = $IPAddress
|
||||
MacAddress = $MacAddress
|
||||
LastSeen = $LastSeen
|
||||
Software = $Software
|
||||
# Force Software to be an array even if it has only one element (for PS 5.1 compatibility)
|
||||
if ($null -eq $Software) {
|
||||
$Software = @()
|
||||
}
|
||||
|
||||
$Inventory = @{
|
||||
ComputerName = $ComputerName
|
||||
User = $User
|
||||
IPAddress = $IPAddress
|
||||
MacAddress = $MacAddress
|
||||
LastSeen = $LastSeen
|
||||
Software = @($Software) # Ensure it's wrapped in an array
|
||||
}
|
||||
|
||||
# In PowerShell 5.1, ConvertTo-Json still flattens single-item arrays in some cases.
|
||||
# We can use a trick to ensure it stays an array or use PS7's -AsArray if available.
|
||||
$Json = $Inventory | ConvertTo-Json -Depth 10
|
||||
if ($Software.Count -eq 1) {
|
||||
# Manual fix for PS 5.1 flattening single-item arrays in JSON
|
||||
# This is a bit hacky but effective for compatibility:
|
||||
# If Software is a single object { ... }, replace it with [ { ... } ]
|
||||
# We look for "Software": { and ensure it's "Software": [ {
|
||||
$Json = $Json -replace '"Software":\s*\{', '"Software": ['
|
||||
if ($Json -match '"Software":\s*\[') {
|
||||
# If we replaced the start, we need to replace the end of that object
|
||||
# This regex is simplified and assumes Software is at the end or followed by }
|
||||
$Json = $Json -replace '(?ms)("Software":\s*\[.*?)\}(\s*\})', '$1}]$2'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Invoke-RestMethod -Uri "$ServerUrl/inventory" -Method Post -Body $Json -ContentType "application/json"
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
bind_address = "0.0.0.0:8080"
|
||||
bind_address = "192.168.178.24:8080"
|
||||
clients_dir = "clients"
|
||||
wol_broadcast = "255.255.255.255:9"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user