Get-NetIPaddress - Issue after disconnecting adapter

Welcome Forums General PowerShell Q&A Get-NetIPaddress - Issue after disconnecting adapter

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #93973

    Points: 0
    Rank: Member

    I am developing a Powershell app for my company to allow our Help Desk to get some details quickly to copy into a ticket. I have the following commands which appears to work and get the desired result

    (Get-NetIPaddress -InterfaceAlias Ethernet*).IPv4Address


    (Get-NetIPaddress -InterfaceAlias Wireless*).IPv4Address

    My issue is if I disconnect the ethernet cable or from the wireless and then re-run the command, I still get the IP addresses I got when I ran the command while connected and cannot find a way to clear this or to read this live.

    I would prefer to keep the Wireless and wired IP Address separate, but is anyone able to suggest a way in which I can keep this to the current IP address (or show nothing if disconnected) and only give me the IP address, no other text.

    Thank you in advance of any help you may be able to provide

  • #93978

    Points: 1,139
    Helping Hand
    Rank: Community Hero

    This is not a PowerShell issue. It is a DHCP lease specification.

    Using DHCP policies to set different lease durations for different device types


    An enterprise has the following types of devices for which network connectivity is required: servers, desktops, printers, desk phones and mobile phones. The admin would like each type of device to have different lease duration-
    • Desktops: Standard lease duration of 8 days (default set for a scope).
    • Printers: Lengthier lease duration of 60 days as they are unlikely to be moved around frequently and are expected to be up and running all the time.
    • Servers: Server computers which are typically expected to be stationery and up all the time can be configured for a lengthy lease duration of 60 days.
    • Desk phones: Again these have similar requirements of lengthy lease duration of 30 days.
    • Mobile phones: These devices are expected to move in and out of the network; hence smaller lease duration of just 8 hours is desired.

    One a nic gets issues an IPA, it will maintain that for the length of time set by policy or until dhcp releases or you manually remove it.

    The old faithful DOS approach


    /release [Adapter] : Sends a DHCPRELEASE message to the DHCP server to release the current DHCP configuration and discard the IP address configuration for either all adapters (if an adapter is not specified) or for a specific adapter if the Adapter parameter is included. This parameter disables TCP/IP for adapters configured to obtain an IP address automatically. To specify an adapter name, type the adapter name that appears when you use ipconfig without parameters.

    Using PoSH

    Release Renew IP Addresses Using PowerShell

    You can use this with-in you own script or you can write a funtion on it. This script using WMI and using the class Win32_NetworkAdapterConfiguration. then using the RenewDHcpLease and ReleaseDHCPlease methods of the class.To know more about this

The topic ‘Get-NetIPaddress - Issue after disconnecting adapter’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort