Set Static IP address from DHCP lease

Welcome Forums General PowerShell Q&A Set Static IP address from DHCP lease

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

3 years, 7 months ago.

  • Author
  • #24920

    Points: 0
    Rank: Member

    Hi all,

    First time poster and Powershell newbie. Not a coder/scripter background so go easy.

    I'm trying to create a script that will get the IPv4 address that a machine is assigned, then statically assign them. I don't know what the IP address will be, it will come from the DHCP server.

    My idea was to 'get' the IPv4 address, subnet mask and gateway (DNS are statically assigned) and assign each to a variable.

    Then 'set' each setting from that variable making it static.

    I can't seem to work out how to 'get' the IPv4 address in a single object so I can assign it to a variable. If I run

    Get-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4

    IPAddress :
    InterfaceIndex : 12
    InterfaceAlias : Ethernet
    AddressFamily : IPv4
    Type : Unicast
    PrefixLength : 22
    PrefixOrigin : Dhcp
    SuffixOrigin : Dhcp
    AddressState : Preferred
    ValidLifetime : 07:03:29
    PreferredLifetime : 07:03:29
    SkipAsSource : False
    PolicyStore : ActiveStore

    I just want the 'IPAddress' parameter. This is ONLY for Windows Server 2012 R2 servers that are newly deployed.

    Like I said, newbie, it's my first script, any help appreciated.



  • #24925

    Points: 0
    Rank: Member

    Well, you have already created an object. You might have written

     $NetIPAddress = Get-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4
    #And then to use the IpAddress, you might call the object's property
  • #24943

    Points: 0
    Rank: Member

    Thanks Brett! That was really helpful.

The topic ‘Set Static IP address from DHCP lease’ is closed to new replies.