PowerCLI

 View Only
  • 1.  Testing Syslog.global.auditRecord.storageEnable variable

    Posted 11 days ago

    This is driving me crazy. I am not a PowerShell expert, so maybe this variable is a format i don't think it is. Can someone tell me why this value is not testing properly:

    Get-VMHost -Name $FQDN| Get-AdvancedSetting -Name Syslog.global.auditRecord.storageEnable

    Name                 Value                Type                 Description                   

    ----                 -----                ----                 -----------                   

    Syslog.global.aud... False                VMHost          

    $test= Get-VMHost -Name $FQDN| Get-AdvancedSetting -Name Syslog.global.auditRecord.storageEnable

    $test.Value

    False

     if($test.Value -eq "False") {write-host "asdf"} 

    The above does not test "true"

    What am i missing on that value type?

    Thank you!

      



  • 2.  RE: Testing Syslog.global.auditRecord.storageEnable variable

    Posted 11 days ago
    Edited by jeffj2000 11 days ago

    I thought maybe a boolean but that doesn't seem to work.




  • 3.  RE: Testing Syslog.global.auditRecord.storageEnable variable

    Posted 11 days ago
    Edited by p0werShelldude 11 days ago

    Because $test.Value is of type Boolean, you will need to test for $true / 1 or $false / 0. You can always check this using the GetType() method; $test.Value.GetType()

    if($test.Value -eq $false) or  if($test.Value -eq 0)

    if($test.Value -eq $true) or  if($test.Value -eq 1)




  • 4.  RE: Testing Syslog.global.auditRecord.storageEnable variable

    Posted 11 days ago

    Thank you! This worked. I will click the recommend button on the thread.




  • 5.  RE: Testing Syslog.global.auditRecord.storageEnable variable

    Posted 11 days ago

    Dear , 

    You're comparing a Boolean to a string.
    $test.Value returns [bool] $false, not the string "False".
    Use:

    if ($test.Value -eq $false) { Write-Host "asdf" }

    Or simply:

    powershell
    if (-not $test.Value) { Write-Host "asdf" } 

    That should work.