So I'm working with Powershell trying to query TPM data from computer objects. I'm having an issue where, when there is no TPM data for a given object, which should be NULL, it evaluates to not NULL. The script below is how I've been experimenting, trying to get my syntax correct. You'll see that I store the value of the msTPM-OwnerInformation in $strTPMString. If it's blank, this should be NULL. However, the if statement always returns Yes, whether or not the var is blank. I've echoed the var and it has no value, I've tried evaluating it to "" and $NULL, I've tried -eq and -ne. Nothing seems to evaluate an empty value to false. Anyone with experience in Powershell and querying AD in this manner that could help me out there?
$strQuery = "Select msTPM-OwnerInformation from 'LDAP://dc=domain,dc=com' where name='123456G'"
$objConnection = New-Object -ComObject "ADODB.Connection"
$objCommand = New-Object -ComObject "ADODB.Command"
$objConnection.Open("Provider=ADsDSOObject;")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = $strQuery
$objRecordSet = $objCommand.Execute()
$strTPMString = $objRecordSet.Fields.item("msTPM-OwnerInformation").Value
echo $strTPMString
if ($strTPMString -eq $NULL)
{
echo "No"
}
else
{
echo "Yes"
}
$objConnection.Close()
$strQuery = "Select msTPM-OwnerInformation from 'LDAP://dc=domain,dc=com' where name='123456G'"
$objConnection = New-Object -ComObject "ADODB.Connection"
$objCommand = New-Object -ComObject "ADODB.Command"
$objConnection.Open("Provider=ADsDSOObject;")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = $strQuery
$objRecordSet = $objCommand.Execute()
$strTPMString = $objRecordSet.Fields.item("msTPM-OwnerInformation").Value
echo $strTPMString
if ($strTPMString -eq $NULL)
{
echo "No"
}
else
{
echo "Yes"
}
$objConnection.Close()