【发布时间】:2017-04-06 00:53:39
【问题描述】:
我有大量需要重命名的 Windows 10 工作站。我试过运行下面的脚本,但得到的错误超出了我当前的 PS 级别。
$computers = Import-Csv "c:\rename-computers\computers.csv"
foreach ($oldname in $computers){
#Write-Host "EmpID=" + $computers.NewName
Rename-Computer -ComputerName $computers.OldName -NewName $computers.NewName -DomainCredential hole\inwall -Force -Restart
}
生产:
重命名计算机:无法将“System.Object[]”转换为类型 参数“ComputerName”需要“System.String”。指定的 方法不受支持。在 \siat-ds0\appdeploy\LabPacks\rename-computers\rename-siat.ps1:4 字符:35 + 重命名-计算机 -ComputerName $computers.OldName -NewName $computers.NewName ... +~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Rename-Computer], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.RenameComputerCommand
我在其他地方看到过类似的关闭线程,但没有提及我收到的错误。
【问题讨论】:
标签: powershell csv batch-processing