{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/xNetworking/issues/17","labels_url":"https://api.github.com/repos/PowerShell/xNetworking/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/xNetworking/issues/17/comments","events_url":"https://api.github.com/repos/PowerShell/xNetworking/issues/17/events","html_url":"https://github.com/PowerShell/xNetworking/issues/17","id":104573273,"number":17,"title":"Breakup IP Address Resource to DHCP and Static","user":{"login":"tysonjhayes","id":651851,"avatar_url":"https://avatars.githubusercontent.com/u/651851?v=3","gravatar_id":"","url":"https://api.github.com/users/tysonjhayes","html_url":"https://github.com/tysonjhayes","followers_url":"https://api.github.com/users/tysonjhayes/followers","following_url":"https://api.github.com/users/tysonjhayes/following{/other_user}","gists_url":"https://api.github.com/users/tysonjhayes/gists{/gist_id}","starred_url":"https://api.github.com/users/tysonjhayes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tysonjhayes/subscriptions","organizations_url":"https://api.github.com/users/tysonjhayes/orgs","repos_url":"https://api.github.com/users/tysonjhayes/repos","events_url":"https://api.github.com/users/tysonjhayes/events{/privacy}","received_events_url":"https://api.github.com/users/tysonjhayes/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/PowerShell/xNetworking/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/PowerShell/xNetworking/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-02T21:18:06Z","updated_at":"2015-09-03T18:37:18Z","closed_at":null,"body":"I think xIPAddress is trying to cover the gambit on what is really two distinct things.  One use case would be trying to assign a NIC a static IP address.  The other would be to assign the NIC to a DHCP server.\r\n\r\nAs the NIC can not have a static IP and be assigned to a DHCP server I prepose we break up the resources to handle those two different tasks.  This way we could have StaticIPAddress and DHCPAddress resources that just handle those use cases.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/PowerShell/xNetworking/issues/comments/137537542","html_url":"https://github.com/PowerShell/xNetworking/issues/17#issuecomment-137537542","issue_url":"https://api.github.com/repos/PowerShell/xNetworking/issues/17","id":137537542,"user":{"login":"tysonjhayes","id":651851,"avatar_url":"https://avatars.githubusercontent.com/u/651851?v=3","gravatar_id":"","url":"https://api.github.com/users/tysonjhayes","html_url":"https://github.com/tysonjhayes","followers_url":"https://api.github.com/users/tysonjhayes/followers","following_url":"https://api.github.com/users/tysonjhayes/following{/other_user}","gists_url":"https://api.github.com/users/tysonjhayes/gists{/gist_id}","starred_url":"https://api.github.com/users/tysonjhayes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tysonjhayes/subscriptions","organizations_url":"https://api.github.com/users/tysonjhayes/orgs","repos_url":"https://api.github.com/users/tysonjhayes/repos","events_url":"https://api.github.com/users/tysonjhayes/events{/privacy}","received_events_url":"https://api.github.com/users/tysonjhayes/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T18:37:18Z","updated_at":"2015-09-03T18:37:18Z","body":"I guess the way I'm thinking of it is the division is really around how we implement the logc.\r\n\r\nTo borrow from [a blog post](http://www.adminarsenal.com/admin-arsenal-blog/using-powershell-to-set-static-and-dhcp-ip-addresses-part-1) I found setting up a static IP is done this way.\r\n\r\n```powershell\r\n$IP = \"10.10.10.10\"\r\n$MaskBits = 24 # This means subnet mask = 255.255.255.0\r\n$Gateway = \"10.10.10.1\"\r\n$Dns = \"10.10.10.100\"\r\n$IPType = \"IPv4\"\r\n\r\n# Retrieve the network adapter that you want to configure\r\n$adapter = Get-NetAdapter | ? {$_.Status -eq \"up\"}\r\n\r\n# Remove any existing IP, gateway from our ipv4 adapter\r\nIf (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) {\r\n    $adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false\r\n}\r\n\r\nIf (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) {\r\n    $adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false\r\n}\r\n\r\n # Configure the IP address and default gateway\r\n$adapter | New-NetIPAddress `\r\n    -AddressFamily $IPType `\r\n    -IPAddress $IP `\r\n    -PrefixLength $MaskBits `\r\n    -DefaultGateway $Gateway\r\n\r\n# Configure the DNS client server IP addresses\r\n$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS\r\n````\r\n\r\nWhere a DHCP is setup like this:\r\n````powershell\r\n$IPType = \"IPv4\"\r\n$adapter = Get-NetAdapter | ? {$_.Status -eq \"up\"}\r\n$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType\r\n\r\nIf ($interface.Dhcp -eq \"Disabled\") {\r\n    # Remove existing gateway\r\n    If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) {\r\n        $interface | Remove-NetRoute -Confirm:$false\r\n    }\r\n\r\n    # Enable DHCP\r\n    $interface | Set-NetIPInterface -DHCP Enabled\r\n\r\n    # Configure the  DNS Servers automatically\r\n    $interface | Set-DnsClientServerAddress -ResetServerAddresses\r\n}\r\n````\r\n\r\nFor DHCP this becomes of Ensure = 'Present' means set DHCP, Ensure = 'Absent' means remove the DHCP.\r\n\r\nStatic means much the same, set these IP Address, or remove the IP addresses.\r\n\r\nI'm also considering we should change the static IP address to be \"assign these IPs and only these IPs\"\r\n\r\nThis would mean if your assigning the IP addresses it would be like this:\r\n@(IP1, IP2, IP3, IP4)\r\n\r\nIf we want to remove one IP address it would need to be assigned like this:\r\n@(IP1, IP2, IP4)\r\n\r\nThe test-targetresource would validate that all given IP addresses, and only those IP addresses are present, if its wrong it would remove all of the IPs and reassign them accordingly.\r\n"}}