Powershell get windows kernel info for multiple devices

Powershell get windows kernel info for multiple devices

# List of computer names
$computers = @("Computer1", "Computer2", "Computer3", "Computer4")

# Function to get kernel information
function Get-KernelInfo {
    param($ComputerName)
    
    try {
        $session = New-PSSession -ComputerName $ComputerName -ErrorAction Stop
        
        $kernelInfo = Invoke-Command -Session $session -ScriptBlock {
            $os = Get-WmiObject Win32_OperatingSystem
            $kernel = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            
            [PSCustomObject]@{
                ComputerName = $env:COMPUTERNAME
                OSVersion = $os.Version
                OSBuildNumber = $os.BuildNumber
                KernelVersion = $kernel.CurrentBuildNumber
                UBR = $kernel.UBR
            }
        }
        
        Remove-PSSession $session
        return $kernelInfo
    }
    catch {
        Write-Warning "Failed to connect to $ComputerName : $_"
        return $null
    }
}

# Fetch kernel info for each computer
$results = foreach ($computer in $computers) {
    Get-KernelInfo -ComputerName $computer
}

# Display results
$results | Format-Table -AutoSize

Leave a Reply

Your email address will not be published. Required fields are marked *