Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By : Thomas Lee, Ed Goad
Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By: Thomas Lee, Ed Goad

Overview of this book

This book showcases several ways that Windows administrators can use to automate and streamline their job. You'll start with the PowerShell and Windows Server fundamentals, where you'll become well versed with PowerShell and Windows Server features. In the next module, Core Windows Server 2016, you'll implement Nano Server, manage Windows updates, and implement troubleshooting and server inventories. You'll then move on to the Networking module, where you'll manage Windows network services and network shares. The last module covers Azure and DSC, where you will use Azure on PowerShell and DSC to easily maintain Windows servers.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Converting IP address from static to DHCP


In some cases, you may need to switch your server's IP address from static, as you did in the Configuring IP addressing recipe, back to DHCP. You might need to do this to re-purpose a server. You may have given it a static IP address to perform a role, but you plan to re-purpose this server and want to configure the server to obtain IP configuration from DHCP.

Getting ready

Run this recipe on the DC2 server. Of course, after running and testing this recipe, you may need to re-run the Configure IP address recipe to ensure DC2 remains correctly configured.

How to do it...

  1. Get the existing IP address information:
$IPType = 'IPv4'$Adapter = Get-NetAdapter | ? {$_.Status -eq 'up' }$Interface = $Adapter | 
         Get-NetIPInterface -AddressFamily $IPType$IfIndex = $Interface.ifIndex$IfAlias = $Interface.InterfacealiasGet-NetIPAddress -InterfaceIndex $Ifindex `
                       -AddressFamily $IPType
  1. Set the interface to get its address from DHCP:
Set...