Came to the conclusion that the remote registry service wasn't enabled or turned on for the remote computer. Instead of enabling it which would open another door into the computer for any intruders, I use the below code:
PowerShell ps = PowerShell.Create()
.AddCommand("Invoke-Command")
.AddParameter("ComputerName", SearcherClass.CurrentComputer)
.AddParameter("Scriptblock", ScriptBlock.Create("Get-Tpm | Select-Object -ExpandProperty TPMPresent"));
This starts a new PowerShell instance and runs the Invoke-Command
to eventually run the Get-Tpm
command which ultimately returns the TPMPresent
property
This is the actual code block that I used to evaluate and return a usable result to my form:
public static string GetTPM()
{
string output = "N/A";
try
{
PowerShell ps = PowerShell.Create()
.AddCommand("Invoke-Command")
.AddParameter("ComputerName", SearcherClass.CurrentComputer)
.AddParameter("Scriptblock", ScriptBlock.Create("Get-Tpm | Select-Object -ExpandProperty TPMPresent"));
foreach(PSObject i in ps.Invoke())
{
output = i.BaseObject.ToString();
}
if (output == "True")
{
output = "Present";
}
else
{
output = "None";
}
return output;
}
catch
{
return "Failed";
}
}