# Set Static IP address from DHCP lease

**URL:** <https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140>\
**Category:** PowerShell Help\
**Created:** [May 3, 2015, 2:37pm UTC](https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140 "2015-05-03T14:37:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-pickard](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@james-pickard](https://forums.powershell.org/u/james-pickard)\
**Post date:** [May 3, 2015, 2:37pm UTC](https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140/1 "2015-05-03T14:37:03Z")

</div>

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 : 130.194.22.224  
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.

cheers

James

---

<div class="post-metadata">

**Author:** ![brett-osiewicz](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@brett-osiewicz](https://forums.powershell.org/u/brett-osiewicz)\
**Post date:** [May 3, 2015, 8:30pm UTC](https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140/2 "2015-05-03T20:30:54Z")

</div>

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

$NetIPAddress.IPAddress
130.194.22.224
```

---

<div class="post-metadata">

**Author:** ![james-pickard](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@james-pickard](https://forums.powershell.org/u/james-pickard)\
**Post date:** [May 4, 2015, 10:37am UTC](https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140/3 "2015-05-04T10:37:24Z")

</div>

Thanks Brett! That was really helpful.  
cheers

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/set-static-ip-address-from-dhcp-lease/4140/4 "2024-05-16T20:45:21Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


