0

Looking to push out a PS script to check for workstations that have a static IP address enabled however the variable always returns as True. I am sure it is something simple I am missing but I can not figure it out.

    $Check = Get-NetIPInterface -ConnectionState Connected | ?{$_.InterfaceAlias -notcontains "Loopback Pseudo-Interface 1" -and $_.Dhcp -notlike "Enabled"}

    If ($Check = $True) {
        Write-Host "Sending Email"
    }
pmac5
  • 65
  • 1
  • 7
  • In short: In PowerShell, use `-eq` / `-ne` for equality / inequality comparisons; `=` is only used for _assignments_. See [this answer](https://stackoverflow.com/a/44248005/45375) to one of the linked duplicates. – mklement0 Jul 13 '21 at 18:38

1 Answers1

0

I was able to get it working using "($Check -ne $null)":

    $Check = Get-NetIPInterface -ConnectionState Connected | ?{$_.InterfaceAlias -notcontains "Loopback Pseudo-Interface 1" -and $_.Dhcp -notlike "Disabled"}

    If ($Check -ne $null) {
        Write-Host "Sending Email"
    }
pmac5
  • 65
  • 1
  • 7