码迷,mamicode.com
首页 > 系统相关 > 详细

PowerShell与系统开局(上)

时间:2015-05-08 18:28:16      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:powershell   hyper-v   

这个需求简直惨不忍睹,就是装电脑配IP,(激活,这话题估计犯禁了)

还有一些安全配置。


以下脚本用PowerShell完成

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混写,格式编码什么的,以及自动输入密码,具体不多说,看代码基本可以看到,而且我这还有注释。


那么问题来了,还少一部分设置IP的部分咋整?

本文出自 “九叔-微软私有云” 博客,请务必保留此出处http://jiushu.blog.51cto.com/972756/1649630

PowerShell与系统开局(上)

标签:powershell   hyper-v   

原文地址:http://jiushu.blog.51cto.com/972756/1649630

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!