【批处理】输入主机名自动完成加域并修改主机名

输入主机名自动完成加域并修改主机名

@echo off
pushd "%~dp0%"
for /f "delims=:" %%i in ('findstr /n "^:JoinDomain$" "%~f0"') do (
	more +%%i "%~f0" > "%temp%\test.ps1"
)
powershell -executionpolicy remotesigned -file "%temp%\test.ps1"
goto :eof

:JoinDomain
$env:domain = 'xxx.local'
$env:domainusername = ‘xxx\joindomain’
$password = "密码" | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($env:domainusername,$password)
$new_hostname = Read-Host 'Please enter a computer name'
Rename-Computer -NewName $new_hostname -DomainCredential $credential
Add-Computer -DomainName $env:domain -OUPath 'OU=xxx,OU=xxxx,OU=PC,DC=xxx,DC=local' -Credential $credential -NewName $new_hostname
msg $env:USERNAME /TIME:5 "Done!"
::shutdown -r -t 15 #使用时去掉注释

posted @ 2023-02-02 15:12  Janexiaoer  阅读(114)  评论(0)    收藏  举报