Home > Net >  Can anyone please explain me what this ?{ $_.VirtualMachine -NE $null} command means in poweshell?
Can anyone please explain me what this ?{ $_.VirtualMachine -NE $null} command means in poweshell?

Time:07-13

Get all the Network Interfaces

$nics = Get-AzNetworkInterface | ?{ $_.VirtualMachine -NE $null}

I am stuck on ?{ $_.VirtualMachine -NE $null} can anyone help?

CodePudding user response:

? is an alias for Where-Object Cmdlet. That means

$nics = Get-AzNetworkInterface | ?{ $_.VirtualMachine -NE $null}

is equivalent to

$nics = Get-AzNetworkInterface | Where-Object { $_.VirtualMachine -NE $null}

Here Where-Object selects objects from a collection based on their property values and $_ is a variable to refer the current item in the collection.

CodePudding user response:

?{ $_.VirtualMachine -NE $null}

NE is Comparision Operator which means Not Equals and $_ means it is using the present item. So, it means finding those Virtual Machines which are not equal to null in the collection.

  • Related