powershell for rename server name

Posted OS Knowledge Base

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell for rename server name相关的知识,希望对你有一定的参考价值。

Rename server name if server has not yet joined AD

$Hostname = "newname"

$username = "Administrator"

$Password = "xxxxxxxx"

$pwd = $Password | ConvertTo-SecureString -asPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential($UserName,$pwd)

Rename-Computer -NewName $Hostname -LocalCredential $credential -Restart

 

Rename server name if server has already joined AD

$Hostname = "newname"

$username = "domainadmin"

$Password = "xxxxxxxx"

$pwd = $Password | ConvertTo-SecureString -asPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential($UserName,$pwd)

Rename-Computer -NewName $Hostname -DomainCredential $credential –Restart

以上是关于powershell for rename server name的主要内容,如果未能解决你的问题,请参考以下文章

Rename-item 认为变量是路径

PermissionError: [Errno 1] for os.rename as quick action

PowerShell:按regex重命名目录项

powershell修改主机名和IP

Powershell 文件重命名语法

shell function/for in/for (())/string concat/has dir/rename using regex/if(())/exit/execute command