A
A
Alexander Semenenko2020-01-30 11:24:27
PowerShell
Alexander Semenenko, 2020-01-30 11:24:27

Where in the if condition, in powershell am I wrong?

Check the instance firewall rules for ip:

PS C:\Users\Administrator> Get-NetFirewallAddressFilter | where RemoteAddress -eq 10.15.0.71 | select InstanceID

InstanceID
----------
{48F93E73-0AE8-476E-ADA3-86AC90361AFF}


The same but for the port:
PS C:\Users\Administrator> Get-NetFirewallPortFilter | where RemotePort -eq 12440-12499 | select InstanceID

InstanceID
----------
{48F93E73-0AE8-476E-ADA3-86AC90361AFF}


This is the same rule, so the InstanceID matches.
Now I drive all this into variables and check what I have in the variables:
PS C:\Users\Administrator> $IP=Get-NetFirewallAddressFilter | where RemoteAddress -eq 10.15.0.71 | select InstanceID
PS C:\Users\Administrator> $Port=Get-NetFirewallPortFilter | where RemotePort -eq 12440-12499 | select InstanceID
PS C:\Users\Administrator> $IP

InstanceID
----------
{48F93E73-0AE8-476E-ADA3-86AC90361AFF}


PS C:\Users\Administrator> $Port

InstanceID
----------
{48F93E73-0AE8-476E-ADA3-86AC90361AFF}


Everything seems to match.
Now I use if:
PS C:\Users\Administrator> if ($IP -eq $Port) {
>>    Write-Host "Совпадает"
>> }
>> else{
>>    Write-Host "Не совпадает"
>> }
>>
Не совпадает


Why "does not match"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2020-01-30
@semenenko88

try like this:

PS C:\Users\Administrator> if ($IP.InstanceID -eq $Port.InstanceID) {
>>    Write-Host "Совпадает"
>> }
>> else{
>>    Write-Host "Не совпадает"
>> }
>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question