{"id":2444,"date":"2013-04-23T13:48:32","date_gmt":"2013-04-23T11:48:32","guid":{"rendered":"http:\/\/wordpress.networknet.nl\/?p=2444"},"modified":"2013-04-23T14:15:30","modified_gmt":"2013-04-23T12:15:30","slug":"poweshell-join-computer-to-the-domain","status":"publish","type":"post","link":"https:\/\/www.networknet.nl\/apps\/wp\/archives\/2444","title":{"rendered":"PowerShell: how to join a computer to active directory and rename hostname?"},"content":{"rendered":"<p>The more you get used to PowerShell the easier it will get to build complex scripts and automate\u00a0your processes. I like PowerShell just because I can copy and paste my scripts from <a href=\"https:\/\/www.networknet.nl\/apps\/wp\/notes\">OneNote<\/a> and reuse them over and over. Preparing my lab, working out the design and later on recreating that for production\u00a0with PowerShell and other unattended scripts has my general\u00a0preference.<\/p>\n<p>On the Windows client, server and BackOffice there are thousands of commandlets today for PowerShell. The following script has helped me to\u00a0automate my process to provision a virtual machine and paste the commands to join the computer to the domain, rename the host name from auto generated Windows setup name and reboot the server.<\/p>\n<p>I am creating virtual machines by manually and this join process takes many clicks. I like the following script to do that job for me. If you are using Hyper-V manager then it can be pasted from the console options directly into the\u00a0virtual machine.<\/p>\n<h3>How to join a windows server to active directory domain with PowerShell?<\/h3>\n<pre class=\"brush:powershell\"># Set windows credential\r\n$SetCredential = Get-Credential\r\n# Join the computer to the domain\r\nAdd-Computer -DomainName networknet.nl -Credential $SetCredential\r\n# Get Computername and Rename with WMI\r\n$Computer = Get-WmiObject Win32_ComputerSystem\r\n$Computernamenew = $Computer.Rename(\"NETWK-WEB-01\", $SetCredential .GetNetworkCredential().Password, $SetCredential .Username)\r\n#Reboot computer to apply new settings\r\nRestart-Computer<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The more you get used to PowerShell the easier it will get to build complex scripts and automate\u00a0your processes. I like PowerShell just because I can copy and paste my scripts from OneNote and reuse them over and over. Preparing my lab, working out the design and later on recreating that for production\u00a0with PowerShell and other unattended scripts has my general\u00a0preference. On the Windows client, server and BackOffice there are thousands of commandlets today for PowerShell. The following script has helped me to\u00a0automate my process to provision a virtual machine and paste the commands to join the computer to the domain, rename the host name from auto generated Windows setup name and reboot the server. I am creating virtual machines by manually and this join process takes many clicks. I like the following script to do that job for me. If you are using Hyper-V manager then it can be pasted from the console options directly into the\u00a0virtual machine. How to join a windows server to active directory domain with PowerShell? # Set windows credential $SetCredential = Get-Credential # Join the computer to the domain Add-Computer -DomainName networknet.nl -Credential $SetCredential # Get Computername and Rename with WMI $Computer = Get-WmiObject Win32_ComputerSystem $Computernamenew = $Computer.Rename(&#8220;NETWK-WEB-01&#8221;, $SetCredential .GetNetworkCredential().Password, $SetCredential .Username) #Reboot computer to apply new settings Restart-Computer<\/p>\n","protected":false},"author":2,"featured_media":1270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[515],"tags":[736,641,15,42,737,11],"class_list":["post-2444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell-microsoft","tag-domain","tag-hostname","tag-join","tag-powershell","tag-rename","tag-script"],"_links":{"self":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/comments?post=2444"}],"version-history":[{"count":12,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2444\/revisions"}],"predecessor-version":[{"id":2457,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/posts\/2444\/revisions\/2457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/media\/1270"}],"wp:attachment":[{"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/media?parent=2444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/categories?post=2444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.networknet.nl\/apps\/wp\/wp-json\/wp\/v2\/tags?post=2444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}