{"id":1468,"date":"2014-02-06T04:42:24","date_gmt":"2014-02-06T04:42:24","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=1468"},"modified":"2014-02-06T04:42:24","modified_gmt":"2014-02-06T04:42:24","slug":"how-to-rename-a-domain-computer-with-windows-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=1468","title":{"rendered":"How to rename a domain computer with Windows PowerShell"},"content":{"rendered":"<div itemprop=\"description\">Use PowerShell to shave time off routine tasks like renaming computers. Here are some commands to try.<\/div>\n<div>\n<p>&nbsp;<\/p>\n<figure><img decoding=\"async\" alt=\"windows8serverscreeshot.png\" src=\"http:\/\/tr1.cbsistatic.com\/hub\/i\/r\/2013\/06\/04\/c5b6b6a3-ccc4-11e2-bc00-02911874f8c8\/resize\/220x165\/windows8serverscreeshot.png?hash=40a8ce9d456391e7e8c979b3a1d7ded7\" \/><\/figure>\n<p>Occasionally it may become necessary to rename a computer in an Active Directory environment. Using the System applet in the Control Panel is the way many administrators have been solving this issue for a long time. Until recently I didn\u2019t think much about the work actually involved in changing a computer name. The typical steps are:&nbsp;<\/p>\n<ol start=\"1\">\n<li>Log on to the workstation.<\/li>\n<li>Access the control panel.<\/li>\n<li>Open the System applet.<\/li>\n<li>Select the change option to change the PC name or domain membership.<\/li>\n<li>Specify a new computer name.<\/li>\n<li>Click OK to save the change.<\/li>\n<li>Click OK on the main properties dialog.<\/li>\n<li>Restart the computer.<\/li>\n<\/ol>\n<p>Depending on the number of things happening when the computer starts, going the long way (or through the Windows GUI) can take anywhere from 2 \u2013 5 minutes. For one computer this may be acceptable, but for multiple PCs this could quickly become very tedious. Especially if you need to visit the computer to make these changes.<\/p>\n<h2>Enter WindowsPowerShell<\/h2>\n<p>Windows PowerShell is quite the helpful administrator\u2019s tool. There are commands for a great many Windows functions without leaving the local machine. Once other tools are added, like Active Directory and Exchange, the capabilities of PowerShell go through the ceiling. In this case, we want to rename a computer using PowerShell. The way to do this using the rename-computer cmdlet is as follows:<\/p>\n<pre>Rename-computer \u2013computername \u201ccomputer\u201d \u2013newname \u201cnewcomputername\u201d \u2013domaincredential domain\\user \u2013force \u2013restart<\/pre>\n<p>&nbsp;<\/p>\n<p>Running this cmdlet and supplying the current computer name for\u00a0<i>\u2013computername<\/i>\u00a0and the new computer name for\u00a0<i>\u2013newname<\/i>\u00a0along with a user account that has permission to perform the function in Active Directory for the\u00a0<i>\u2013domaincredential<\/i>\u00a0parameter. \u00a0Supplying the\u00a0<i>\u2013force<\/i>parameter ensures that the changes will be applied and \u2013restart will force the computer to restart after the change is made, still a requirement for renaming computers.<\/p>\n<p>This may seem like the same amount of effort as using the screens to change the name, but I assure you, even for one machine, it is faster. When I used this recently, I didn\u2019t need to logon to complete the action and as soon as the command completed, the computer was rebooting. Since the client I renamed was not sitting in front of me, by the time I walked across my office to see if it was going to get renamed, the system was already shutting down as directed by the\u00a0<i>\u2013restart<\/i>\u00a0switch.<\/p>\n<p>Where this gets really handy is if you need to rename several computers. The cmdlet doesn\u2019t really change all that much either, with the biggest difference being how the \u2013computername and \u2013newname parameters are handled. For example, to get this to work with multiple computers you might do something like this:<\/p>\n<p><b>\u00a0<\/b><\/p>\n<pre>$computers = Get-adcomputer | where {$_.name \u2013like \u201csales-*\u201d}\r\n\r\n$num = 0\r\n\r\nForeach($computer in $computers)\r\n\r\n{\r\n\r\nFor($num=1;$num \u2013lt $computers.count;$num++)\r\n\r\n{\r\n\r\nRename-computer \u2013computername $computer \u2013newname \u201cs-$num\u201d \u2013domaincredential domain\\user \u2013force \u2013restart\r\n\r\n        }<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Since the newname parameter is essentially incrementing the same name by one for up to the total number of computers this way will also allow a fairly quick renaming of computers. \u00a0Unless your environment rolls PCs over frequently, I would imagine the single cmdlet would be of most use with the specified computername and newname.<\/p>\n<p>There are many other ways to tackle this problem, although you will likely need lists or loops of some kind to plow through the items. You might choose to populate your computers list another way, maybe by getting the names of existing systems from Active Directory:<\/p>\n<p><b>Note<\/b>: Appending the \u2013whatif switch on the Rename-computer cmdlet will display what the command would do if it actually executed. This can give you an idea of the performance without actually changing the computer name.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Use PowerShell to shave time off routine tasks like renaming computers. Here are some commands to try. &nbsp; Occasionally it may become necessary to rename a computer in an Active Directory environment. Using the System applet in the Control Panel is the way many administrators have been solving this issue for a long time. Until [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[],"class_list":["post-1468","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1468"}],"version-history":[{"count":2,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1468\/revisions"}],"predecessor-version":[{"id":1470,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/1468\/revisions\/1470"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}