【问题标题】:PowerShell calling function to change the computer machine name errorPowerShell调用函数更改计算机机器名错误
【发布时间】:2014-06-01 22:35:08
【问题描述】:
Function ChangeName([string]$firstname, [string]$secondname)
{
    net user administrator /active:yes
    Write-Host "The new student machine name is: $firstname-S$secondname"

    wmic computersystem where name="$(Get-WmiObject Win32_Computersystem).name" call rename name="$newname"
}

ChangeName "A" "B"

错误信息: 无效的动词切换

【问题讨论】:

  • 你在哪里定义了$newname?
  • @user3545795 但是ChangeName "A" "B" 没有在任何地方设置$newname 变量。您需要在 ChangeName 函数中使用类似 $newname = "$firstname-$secondname" 的内容才能使用它。

标签: windows function powershell rename wmic


【解决方案1】:

为什么不使用内置的Rename-Computer 命令?

【讨论】:

  • 我需要使用 PowerShell 2.0
  • 哎哟。你真的不能更新到至少3.0吗? 2.0 有点长(2009 年)。 :-)
  • 我在VM中运行,如何在VM中升级Powershell?
  • 在这里microsoft.com/en-us/download/details.aspx?id=34595 下载适合您操作系统的正确版本并运行它。支持的操作系统是 Windows 7 Service Pack 1、Windows Server 2008 R2 SP1、Windows Server 2008 Service Pack 2 及更高版本。
猜你喜欢
  • 2020-07-27
  • 1970-01-01
  • 2020-10-06
  • 2016-02-29
  • 2011-09-06
  • 2023-01-13
  • 2017-01-01
  • 2011-06-25
  • 1970-01-01
相关资源
最近更新 更多