user1709091
user1709091

Reputation:

How to rewrite this powershell cmdlet to produce specific output?

I am not good with PS but I need help with this..

Get-WmiObject -class DCIM_BIOSEnumeration -Namespace root\dcim\sysman | Where-Object {$_.AttributeName -Match "Trusted Platform Module Activation"} | Select CurrentValue 

When it runs, it will return either a 1 or 2 as the CurrentValue.

I need the script to output "Detected" if the result is 2 and nothing (null) if it is 1.

Anyone able to help out? Thanks !!

Upvotes: 1

Views: 122

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174855

Use an if statement to determine whether to output "Detected" or not:

$CurrentValue = Get-WmiObject -class DCIM_BIOSEnumeration -Namespace root\dcim\sysman | Where-Object {
  $_.AttributeName -Match "Trusted Platform Module Activation"
} | Select-Object -ExpandProperty CurrentValue

if($CurrentValue -eq 2) {
    "Detected"
}

Upvotes: 2

Related Questions