When using the PowerCLI Get-VM cmdlet combined with the Guest property (e.g., Get-VM <VMName> | Select-Object -ExpandProperty Guest), users can retrieve IP addresses, but the Subnet Mask and Default Gateway information is not returned.
To retrieve the subnet mask and default gateway, users can execute a command directly within the guest operating system using the Invoke-VMScript cmdlet. This requires that VMware Tools is running.
Command example and output is following.
PS C:\Users\Administrator> Invoke-VMScript -VM "Win2022" -ScriptType PowerShell -ScriptText "ipconfig | findstr /R 'IPv4 Subnet Default'"
WARNING: The version of VMware Tools on VM 'Win2022' is out of date and may cause Invoke-VMScript to work improperly.
ScriptOutput
-------------------------------------------------------------------------------------------------------------------------------------------
| IPv4 Address. . . . . . . . . . . : 192.168.1.2
| Subnet Mask . . . . . . . . . . . : 255.255.255.0
| Default Gateway . . . . . . . . . : 192.168.1.254
|
-------------------------------------------------------------------------------------------------------------------------------------------
If Invoke-VMScript execution fails, please refer to the following Knowledge.