当前位置:   article > 正文

通过AD域远程修改计算机名(含批量脚本)_ad域修改计算机名

ad域修改计算机名

公司内的计算机名常常需要统一规范,但告知员工整改之后往往整改进度推进缓慢,那么有没有什么方法能远程修改掉不合规的机器名呢?

答案是肯定的,只需在域控执行以下执行以下命令:

netdom renamecomputer 要修改的计算机名 /newname:新的计算机名 /userd:域名\管理员名 /password:密码

之后弹出一个询问框,输入y即可,如果不想进行确认,一律强制执行,则在上述命令行后加上参数 /force。

修改计算机名后,用户需重启计算机才能生效,也可通过下面的命令远程重启对方机器:

/usero:本地管理员账号 /passwordo:本地管理员密码 /reboot:过多少秒自动重启

 

一个例子:

netdom renamecomputer oldname /newname:newname /userd:hirain.com\Administrator /password:123456

/usero:localAdmin /passwordo:ABCDEF /reboot:1


问题二,如果现在公司内有一大批机器需要修改机器名,如何批量实现?

我的想法是编写一个批量脚本生成程序,建一个csv文件,将现在的机器名放在第一列,想要修改成的用户名放在第二列,运行脚本自动生成批量脚本。

脚本生成程序的C#代码如下:


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace userFliter
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. String[] org = File.ReadAllLines("d:/1.csv", Encoding.Default);
  14. String newText = null;
  15. newText = coding(org, newText);
  16. StreamWriter sw = new StreamWriter("d:/code.bat");
  17. sw.Write(newText);
  18. sw.Flush();
  19. sw.Close();
  20. }
  21. static private String coding(String[] oldLine, String newText)
  22. {
  23. String oldName = null;
  24. String newName = null;
  25. for (int i = 0; i < oldLine.Length; i++)
  26. {
  27. oldName = oldLine[i].Substring(0, oldLine[i].IndexOf(","));
  28. newName = oldLine[i].Substring(oldLine[i].IndexOf(",") + 1);
  29. newText = newText + "echo "+oldName+" >>D:\\log.txt\r\n";
  30. newText = newText + "netdom renamecomputer " + oldName + " /newname:" + newName + " /userd:域\\管理员 /passwordd:管理员密码 /force>>D:\\log.txt\r\n";
  31. newText = newText + "echo.>>D:\\log.txt\r\n";
  32. }
  33. newText = newText + "echo ok!\r\n";
  34. newText = newText + "pause\r\n";
  35. return newText;
  36. }
  37. }
  38. }


生成的脚本打开后能看到管理员密码,可以通过软件转化为exe文件,而后加壳,避免该问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/810323
推荐阅读