我正在编写一个脚本来自动化一些AWS启动的Windows服务器实例。 我有DNS的变化,join域的部分没关系,但我在迭代命名空间时遇到了问题…例如;
机器自动生成的名字是:WIN-JDK2349DFJR我想让脚本检查AD,看看名称(如图像N)是否正在使用,如果是,则命名机器映像N + 1。
服务器启动,自动命名(WIN-JDK2349DFJR)。 脚本调用 – 脚本检查AD:三台服务器命名为“images1,images2,images3”脚本将DNS更改为本地DC,将名称更改为“images4”,join域并重新启动。
我不确定如何编写PowerShell脚本来检查Active Directory中的计算机名称imageN,如果在名为imageN的Active Directory中存在具有N的计算机帐户,则增加N.
特洛伊,
我认为从操作的angular度来看,存在一些问题。
下面回答你的问题的答案(“迭代命名空间的麻烦”)。 我的答案后,你会明白为什么我认为你会有其他问题。
回答如何编写PowerShell脚本来迭代命名空间。
import-module ActiveDirectory $counter = 0 $nameselected = "no" $server = "image$counter" $ErrorActionPreference = 'SilentlyContinue' Do { Write-Host "Checking for existance of $server." if (Get-ADComputer -Identity $server) { Write-Host "Count is $counter." $global:counter++ $server = "image$counter" Write-Host "New count is $counter." } } Until ( ( -not $( Get-ADComputer -Identity $server)) ) $nameslected = "yes" Write-Host "The name will be $server." Write-Host "Replace this line with the with your function for changing DNS or joining the domain."
可能的问题,你将要试图做到这一点。