Unable to convert system object into system INT

Dear All

I am using the below command to gain the MTU value for the ethernet adaptor:

$MTU=Get-NETIPInterface | where-object {$_.InterfaceAlias -like “Ethernet 2”} | format-table -HideTableHeaders NlMtu

which does product the correct result however when I use the $MTU variable in the below command I get the error “Cannot convert system object to system.int which is required by the buffersize”

test-connection -TargetName INSERTPCNAMEHERE -BufferSize $MTU |Format-Table -HideTableHeaders status

I have read a few other online post that suggested putting [int] at the beginning or within the cmdlet but this has not worked.

Can anyone give me advise on how to solve my issue?

just to add we are using powershell 7.1 for this hence we are using the parameter TargetName

Thanks

Ben

Format-* commands should strictly be used for console output for human eyes, it destroys objects so you should avoid it for what you’re trying to do.

$MTU=Get-NETIPInterface | where-object {$_.InterfaceAlias -like “Ethernet 2”} | Select-Object -ExpandProperty NlMtu
test-connection -TargetName INSERTPCNAMEHERE -BufferSize $MTU

Try Select-Object with -ExpandProperty parameter instead of Format-Table.

$MTU=Get-NETIPInterface | where-object {$_.InterfaceAlias -like “Ethernet 2”} | Select-Object -ExpandProperty NlMtu

This will extract the value of the property.