gpt4 book ai didi

PowerShell Rename-Computer 问题——带下划线的名称

转载 作者:行者123 更新时间:2023-12-04 17:22:02 24 4
gpt4 key购买 nike

我正在使用 Rename-Computer 编写 PowerShell 脚本,但遇到了一个奇怪的问题:

PS C:\Users\Administrator> Rename-Computer -NewName 395_s2

Rename-Computer : Skip computer 'ztest' with new name '395_s2' because the new name is not valid. The new computer name entered is not properly formatted. Standard names may contain letters (a-z, A-Z), numbers (0-9), and hyphens (-), but no spaces or periods (.). The name may not consist entirely of digits, and may not be longer than 63 characters.


我真的希望能够在机器名称中使用下划线,并且 -Force 标志不会更改输出。
当我在计算机->系统属性->计算机名称/域更改中手动输入相同的名称时,它会询问:

Do you want to use this computer name?

The name "395_s2" contains non-standard characters. This might cause problems with some applications or network hardware.


我可以选择是并覆盖非标准字符。有没有办法直接在 PowerShell 中执行此操作?

最佳答案

使用 WMI 似乎没有这个限制。我刚刚在我自己的电脑上测试过

(Get-WmiObject Win32_ComputerSystem).Rename("te_st")

它不是 Rename-Computer,但它看起来有效。也将重新发布我对 Mad 帖子的评论。有一篇关于计算机名称和下划线的非常好的帖子。 The use of the underscore in host names

引用其中一个答案并同意 Mad Scientist

Though its valid to use underscores it not a recommended practice.

关于PowerShell Rename-Computer 问题——带下划线的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24790701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com