Computer Details using JSON post - Knowledgebase - CLOUDRAIN

Computer Details using JSON post Print

  • Computer Details using JSON post
  • 0

# Collect system details
$ComputerName = $env:COMPUTERNAME
$Manufacturer = (Get-WmiObject Win32_ComputerSystem).Manufacturer
$Model = (Get-WmiObject Win32_ComputerSystem).Model
$SerialNumber = (Get-WmiObject Win32_BIOS).SerialNumber
$OS = Get-WmiObject Win32_OperatingSystem
$OSName = $OS.Caption
$OSVersion = $OS.Version
$CPUModel = (Get-WmiObject Win32_Processor).Name
$RAMCapacity = [math]::Round(((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory / 1GB), 2)
$HardDiskSize = [math]::Round(((Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DeviceID -eq "C:"}).Size / 1GB), 2)
$IPAddress = (Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | Select-Object -ExpandProperty IPAddress)[0]

# Get physical disk information using Get-PhysicalDisk
$physicalDisks = Get-PhysicalDisk


# Get details about the last patch installed
$lastPatch = Get-HotFix | Sort-Object -Property InstalledOn -Descending | Select-Object -First 1


$CurrentTimestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") # Get current timestamp

# Get logged-in user and domain
$LoggedInUser = $env:USERNAME
$Domain = $env:USERDOMAIN

# Get Administrators group members
$AdminGroupMembers = (Get-LocalGroupMember -Group "Administrators" | Select-Object -ExpandProperty Name) -join ', '

#CPU Details
$cpuInfo = Get-WmiObject Win32_Processor


# Get members of the Remote Desktop Users group
$rdGroup = 'Remote Desktop Users'
$rdMembers = Get-LocalGroupMember -Group $rdGroup | Select-Object -ExpandProperty Name

# Create a JSON object with system details
$systemDetails = @{
computer_name = $ComputerName
manufacturer = $Manufacturer
model = $Model
serial_number = $SerialNumber
os_name = $OSName
os_version = $OSVersion
cpu_model = $CPUModel
ram_capacity = $RAMCapacity
hard_disk_size = $HardDiskSize
ip_address = $IPAddress
logged_in_user = $LoggedInUser # Add logged-in user
domain = $Domain # Add domain
admin_group_members = $AdminGroupMembers
rdp_group_members = $rdMembers -join ', ' # Join names into a single string
LastPatchKBNumber = $lastPatch.HotFixID
LastPatchDescription = $lastPatch.Description
LastPatchInstalledOn = $lastPatch.InstalledOn
CPUManufacturer = $cpuInfo.Manufacturer
CPUModel = $cpuInfo.Name
NumberOfCore = $cpuInfo.NumberOfCores
NumberOfLogicalProcessors = $cpuInfo.NumberOfLogicalProcessors
CPUArchitecture = $cpuInfo.Architecture
CPUSerialNumber = $cpuInfo.ProcessorId

 

 

timestamp = $CurrentTimestamp # Add timestamp to the object
}

# Convert the details to JSON
$systemDetailsJson = $systemDetails | ConvertTo-Json

# Send system details to the server via HTTP POST
Invoke-RestMethod -Uri 'https://test.test.in/save_computer.php' -Method Post -Body $systemDetailsJson -ContentType 'application/json'


Was this answer helpful?

« Back

Powered by WHMCompleteSolution