这个需求简直惨不忍睹,就是装电脑配IP,(激活,这话题估计犯禁了)
还有一些安全配置。
以下脚本用PowerShell完成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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
|
这里用到了PowerShell和CMD混写,格式编码什么的,以及自动输入密码,具体不多说,看代码基本可以看到,而且我这还有注释。
本文转自 九叔 51CTO博客,原文链接:http://blog.51cto.com/jiushu/1649630,如需转载请自行联系原作者