35 lines
2.2 KiB
PowerShell
35 lines
2.2 KiB
PowerShell
function Get-SamsaraSystem {
|
|
param($Result)
|
|
$Result.data = [ordered]@{
|
|
hostname = [Environment]::MachineName; platform = 'windows'
|
|
collection_source = 'Local Windows read-only collection'
|
|
operating_system = 'Not collected'; os_version = 'Not collected'; os_build = 'Not collected'
|
|
product_type = 0; last_boot = 'Not collected'; ip_addresses = @(); network_adapters = @()
|
|
domain = 'Not collected'; domain_joined = $null
|
|
}
|
|
Invoke-SamsaraRead $Result 'OS identity' {
|
|
$os = Get-CimInstance -ClassName Win32_OperatingSystem -Property Caption,Version,BuildNumber,LastBootUpTime,ProductType -ErrorAction Stop
|
|
$years = @{ '14393' = '2016'; '17763' = '2019'; '20348' = '2022'; '26100' = '2025' }
|
|
if ([int]$os.ProductType -notin @(2,3) -or -not $years.ContainsKey([string]$os.BuildNumber)) {
|
|
throw 'Unsupported Windows release or workstation edition.'
|
|
}
|
|
$Result.data.operating_system = [string]$os.Caption
|
|
$Result.data.os_version = $years[[string]$os.BuildNumber]
|
|
$Result.data.os_build = [string]$os.BuildNumber
|
|
$Result.data.kernel_version = [string]$os.Version
|
|
$Result.data.product_type = [int]$os.ProductType
|
|
$Result.data.last_boot = $os.LastBootUpTime.ToUniversalTime().ToString('o')
|
|
}
|
|
Invoke-SamsaraRead $Result 'Computer domain membership' {
|
|
$computer = Get-CimInstance -ClassName Win32_ComputerSystem -Property Domain,PartOfDomain -ErrorAction Stop
|
|
$Result.data.domain = [string]$computer.Domain
|
|
$Result.data.domain_joined = [bool]$computer.PartOfDomain
|
|
}
|
|
Invoke-SamsaraRead $Result 'Network adapter configuration' {
|
|
$adapters = @(Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IPEnabled = True' -Property Description,IPAddress -ErrorAction Stop)
|
|
$Result.data.network_adapters = @($adapters | ForEach-Object { [string]$_.Description })
|
|
$Result.data.ip_addresses = @($adapters | ForEach-Object { foreach ($address in $_.IPAddress) { [string]$address } })
|
|
}
|
|
$Result.limitations += 'Identity and addresses are local observations. No DNS probes or Active Directory enrichment were performed.'
|
|
}
|