MDT通过PowerShell脚本自定义变量(自定义计算机名)

 

1.如果在Preinstall阶段运行PowerShell脚本,则需要做如下设置:

打开DeploymentShare属性-Windows PE - Features,选中如下三项,然后Update DeploymentShare

2.在Preinstall阶段添加 Run PowerShell Script,脚本路径:D:\DeploymentShare\Scripts\renamepc.ps1

 renamepc.ps1脚本内容如下:

Import-Module ZTIUtility.psm1
$sn = $TSENV:UUID
$strcname = "abc" + $sn
$Tsenv:OSDCOMPUTERNAME = $strcname

gci TSenv: |Out-File \\10.160.15.249\DeploymentShare$\test2.log -Append

 参考:http://c-nergy.be/blog/?p=3964

 

=========================================================================================

1.在Deploymentshare\Scripts下新建tv.ps1脚本,内容如下:

# Determine where to do the logging 
$TSenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $TSenv.Value("LogPath")  
$logFile = "$logPath\$($myInvocation.MyCommand).log"

$TSenv.Value("ts01") = (gwmi win32_computersystem).manufacturer   #自定义变量ts01

# Start the logging 
Start-Transcript $logFile
Write-Host "Logging to2222 $logFile"

$TSenv.Value("ts02") = “abc”

# Stop logging 
Stop-Transcript

2.在CustomSettings.ini中添加自定义变量ts01

Properties=ComputerTypeName, ComputerSerialNumber,tv01

3.在TS中运行tv.ps1脚本,如下:

 

然后调用ps1中自定义的 ts01变量

 

===============================================================================================

通过.ps1脚本自定义计算机名:

tv.ps1脚本内容:

# Determine where to do the logging 
$TSenv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
$logPath = $TSenv.Value("LogPath")  
$logFile = "$logPath\$($myInvocation.MyCommand).log"


# Start the logging 
Start-Transcript $logFile

$TSenv.Value("OSDComputername")="abc"
Import-Module ZTIUtility.psm1 #未生效
gci tsenv: |Out-File C:\MININT\test2.log #未生效

# Stop logging 
Stop-Transcript

2.将脚本放到Preinstall中,如下,CustomSettings.ini中无需其他设置,安装过程中默认的MINIT格式计算机名最后会被.ps1脚本中名称覆盖

posted on 2020-06-22 14:50  momingliu11  阅读(1988)  评论(0编辑  收藏  举报