RunOnce在重新启动时使用随机名称重命名计算机名 [英] RunOnce to rename a Computername with a random name on reboot

查看:202
本文介绍了RunOnce在重新启动时使用随机名称重命名计算机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是一个学习中心,有时由于各种原因,我们无法对机器进行系统准备.当我不对计算机进行系统准备时,最终我用同一计算机名克隆一台计算机25次.

We are a learning center and sometimes we are not able to sysprep the machines for different reasons. When I do not sysprep the machines, I end up cloning a machine 25 times with the same computername.

然后我必须手动在每个工作站上更改计算机名称,然后再重新启动计算机.

I then have to go manually on each station and change the computername and restart them after.

我想知道我是否可以使用关闭机器(预克隆)之前要使用的批处理文件或powershell脚本.然后,在下次重新引导(仅一次)时,计算机将随机更改计算机名,从而为我节省了很多时间.

I was wondering if I could use a batch file or powershell script that I would do before shutting down my machine (pre-cloning). Then, on next reboot (only once) the computer would randomly change the Computername and therefore save me alot of time.

我正在Windows XP到Windows Server 2012R2上执行此操作.在所有这些操作系统下均可使用的独特解决方案是不可思议的,但我主要在Server 2008+上做到这一点.我不介意将批处理文件用于WinXP-Win7,而将Powershell用于Windows 2008至2012!

I am doing this under Windows XP to Windows Server 2012R2. A unique solution working under all those OSes would be magic but I mostly do this on Server 2008+. I dont mind using a batch file for WinXP-Win7 and powershell for Windows 2008 to 2012 for example!

谢谢大家!

推荐答案

您可以使用Get-Random cmdlet生成随机名称.

You can generate a random name using the Get-Random cmdlet.

# Set allowed ASCII character codes to Uppercase letters (65..90), 
$charcodes = 65..90

# Convert allowed character codes to characters
$allowedChars = $charcodes | ForEach-Object { [char][byte]$_ }

$LengthOfName = 10
# Generate computer name
$pw = ($allowedChars | Get-Random -Count $LengthOfName) -join ""

您可以使用cmdlet重命名计算机来更改计算机名称.并将其设置为运行一次,最简单的方法是将一个条目添加到注册表项

You can change a computer name with the cmdlet Rename-Computer. And to set it to run once, the easiest way would be to add an entry to the registry key

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce   

将使用您的脚本调用PowerShell.

that will invoke PowerShell with your script.

这篇关于RunOnce在重新启动时使用随机名称重命名计算机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆