Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

wygeneruj artykuł do medium.com dostosowując go do tego kodu, co wyżej oraz tytułu: How…

  1. User

    wygeneruj artykuł do medium.com dostosowując go do tego kodu, co wyżej oraz tytułu: How to Check the TPM Version and Status in PowerShell or Go

    package main

    import ( "flag" "fmt" "os/exec" "strings" )

    var ( viewActivated bool viewEnabled bool viewOwned bool viewManufacturerId bool viewManufacturerIdTxt bool viewManufacturerVersion bool viewManufacturerVersionFull bool viewManufacturerVersionInfo bool viewPhysicalPresenceVersion bool viewSpecVersion bool viewPSComputerName bool viewHelp bool )

    func init() { flag.BoolVar(&viewActivated, "a", false, "View IsActivated_InitialValue") flag.BoolVar(&viewEnabled, "e", false, "View IsEnabled_InitialValue") flag.BoolVar(&viewOwned, "o", false, "View IsOwned_InitialValue") flag.BoolVar(&viewManufacturerId, "id", false, "View ManufacturerId") flag.BoolVar(&viewManufacturerIdTxt, "idt", false, "View ManufacturerIdTxt") flag.BoolVar(&viewManufacturerVersion, "mv", false, "View ManufacturerVersion") flag.BoolVar(&viewManufacturerVersionFull, "mvf", false, "View ManufacturerVersionFull20") flag.BoolVar(&viewManufacturerVersionInfo, "mvi", false, "View ManufacturerVersionInfo") flag.BoolVar(&viewPhysicalPresenceVersion, "ppvi", false, "View PhysicalPresenceVersionInfo") flag.BoolVar(&viewSpecVersion, "sv", false, "View SpecVersion") flag.BoolVar(&viewPSComputerName, "psc", false, "View PSComputerName") flag.BoolVar(&viewHelp, "h", false, "View help screen")

    flag.Parse()
    

    }

    func main() { if viewHelp { printHelp() return }

    cmd := exec.Command("powershell", "-Command", "$tpm = Get-WmiObject -Namespace \"Root\\CIMv2\\Security\\MicrosoftTpm\" -Class Win32_Tpm; Write-Host \"SpecVersion: $($tpm.SpecVersion)\"; Write-Host \"ManufacturerID: $($tpm.ManufacturerID)\"")
    output, err := cmd.Output()
    if err != nil {
        fmt.Println("Błąd podczas wykonania polecenia PowerShell:", err)
        return
    }
    
    info := string(output)
    lines := strings.Split(info, "\n")
    for _, line := range lines {
        line = strings.TrimSpace(line)
        printLine(line)
    }
    

    }

    func printLine(line string) { if viewSpecVersion && strings.HasPrefix(line, "SpecVersion:") { fmt.Println(line) } if viewManufacturerId && strings.HasPrefix(line, "ManufacturerID:") { fmt.Println(line) } if viewActivated && strings.HasPrefix(line, "IsActivated_InitialValue:") { fmt.Println(line) } if viewEnabled && strings.HasPrefix(line, "IsEnabled_InitialValue:") { fmt.Println(line) } if viewOwned && strings.HasPrefix(line, "IsOwned_InitialValue:") { fmt.Println(line) } if viewManufacturerIdTxt && strings.HasPrefix(line, "ManufacturerIdTxt:") { fmt.Println(line) } if viewManufacturerVersion && strings.HasPrefix(line, "ManufacturerVersion:") { fmt.Println(line) } if viewManufacturerVersionFull && strings.HasPrefix(line, "ManufacturerVersionFull20:") { fmt.Println(line) } if viewManufacturerVersionInfo && strings.HasPrefix(line, "ManufacturerVersionInfo:") { fmt.Println(line) } if viewPhysicalPresenceVersion && strings.HasPrefix(line, "PhysicalPresenceVersionInfo:") { fmt.Println(line) } if viewPSComputerName && strings.HasPrefix(line, "PSComputerName:") { fmt.Println(line) } }

    func printHelp() { fmt.Println("cTMP Help:") flag.PrintDefaults() }

  2. Assistant

    How to Check the TPM Version and Status in PowerShell or Go

    In this article, we will learn how to check the TPM (Trusted Platform Module) version and status using either PowerShell or Go programming language. TPM is a hardware-based security feature that provides cryptographic functions to secure sensitive data and ensure platform integrity.

    Checking TPM Version and Status with PowerShell

    To check the TPM version and status using PowerShell, we can use the "Get-WmiObject" cmdlet to retrieve information from the "Win32_Tpm" class in the "Root\CIMv2\Security\MicrosoftTpm" namespace.

    $tpm = Get-WmiObject -Namespace "Root\CIMv2\Security\MicrosoftTpm" -Class Win32_Tpm
    Write-Host "SpecVersion: $($tpm.SpecVersion)"
    Write-Host "ManufacturerID: $($tpm.ManufacturerID)"
    

    The above PowerShell code retrieves the TPM information and outputs the SpecVersion and ManufacturerID.

    To execute the PowerShell code in Go, we can use the os/exec package to run the PowerShell command and capture its output.

    Here's an example Go code to check the TPM version and status using PowerShell:

    package main
    
    import (
    	"fmt"
    	"os/exec"
    	"strings"
    )
    
    func main() {
    	cmd := exec.Command("powershell", "-Command", "$tpm = Get-WmiObject -Namespace \"Root\\CIMv2\\Security\\MicrosoftTpm\" -Class Win32_Tpm; Write-Host \"SpecVersion: $($tpm.SpecVersion)\"; Write-Host \"ManufacturerID: $($tpm.ManufacturerID)\"")
    	output, err := cmd.Output()
    	if err != nil {
    		fmt.Println("Error executing PowerShell command:", err)
    		return
    	}
    
    	info := string(output)
    	lines := strings.Split(info, "\n")
    	for _, line := range lines {
    		line = strings.TrimSpace(line)
    		fmt.Println(line)
    	}
    }
    

    In the above Go code, we execute the PowerShell command using the exec.Command function and capture the output using cmd.Output(). We then split the output into lines and print each line.

    You can customize the Go code by adding flags to view specific TPM information such as activation status, enabled status, ownership status, manufacturer ID, version, and more.

    Conclusion

    In this article, we learned how to check the TPM version and status using either PowerShell or Go programming language. By utilizing the "Get-WmiObject" cmdlet in PowerShell or executing PowerShell commands in Go, we can retrieve the TPM information and display it in a convenient format. Understanding the TPM version and status is crucial for ensuring the security and integrity of the platform.