|
c:/"Microsoft Toolkit 2.4.3.exe"
echo ==========================
echo Hyper-V开局脚本,至少需要PowerShell3.0,即Windows Server 2012系统
echo 1、装Hyper-V角色
echo 2、改名加域
#echo 3配置加入本地管理员的域账户
echo ==========================
$zone1 = Read-Host("请输入计算机名称(netbios):")
cls
$theend2 = "shutdown /r /t 1 "
#下面这句开始装角色
Install-WindowsFeature hyper-v -IncludeManagementTools
$mysecret="123.abcdefg"
$mysecret|ConvertTo-SecureString -AsPlainText -Force |ConvertFrom-SecureString|Out-File C:\adscript\xxx.txt -Encoding utf8
$securestring=(Get-Content C:\adscript\xxx.txt).ToString() | ConvertTo-SecureString
$ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($secureString)
$serverpass = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($ptr)
$UserName = "tech\wdsserver" #定义管理员账户名称
$Password = ConvertTo-SecureString $serverpass -AsPlainText –Force
$cred = New-Object System.Management.Automation.PSCredential($UserName,$Password)
#下面加域
Add-Computer -NewName $zone1 -DomainName tech.bitauto.com -Credential $cred -OUPath "OU=HyperV计算机组,DC=tech,DC=bitauto,DC=com" -Force
#前面可以加变量$usertech,配置需要加入本地管理员的账户
#net localgroup /add administrators tech\$usertech
echo 5秒后重启计算机……如前期报错,此时可强制关闭窗口
Start-Sleep –s 5
echo $theend2 |Out-File theend2.cmd -Encoding Default
.\theend2.cmd
|
|
|