Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 重新命名多台PC';然后从CSV文件加入域_Windows_Powershell_Dns_Hostname - Fatal编程技术网

Windows 重新命名多台PC';然后从CSV文件加入域

Windows 重新命名多台PC';然后从CSV文件加入域,windows,powershell,dns,hostname,Windows,Powershell,Dns,Hostname,我需要能够重新命名,然后加入一个域,多台电脑的CSV文件 CSV的内容包括:- oldpcname1,newpcname1 oldpcname2,newpcname2 等等 代码如下:- $File = "C:\computer_names.csv" $domain = "MBTEST.LOCAL" $password = "password" | ConvertTo-SecureString -asPlainText -Force

我需要能够重新命名,然后加入一个域,多台电脑的CSV文件

CSV的内容包括:-

oldpcname1,newpcname1
oldpcname2,newpcname2
等等

代码如下:-

$File = "C:\computer_names.csv"
$domain = "MBTEST.LOCAL"
$password = "password" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\Administrator"
$user2 = "administrator"
$pass2 = "pa55w0rd" | ConvertTo-SecureString -asPlainText -Force
$lcred = New-Object System.Management.Automation.PsCredential($user2, $pass2)
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
 
 
$computerList= Import-Csv -Path $File `
                          -Delimiter "," `
                          -Header OldName,NewName
 
foreach ($Computer in $computerList)
{
Rename-Computer -ComputerName $Computer.OldName -NewName $Computer.NewName -LocalCredential $lcred 
Add-Computer -ComputerName $Computer.OldName -Domain 'MBTEST.local' -Domaincredential $credential -LocalCredential $lcred -Restart 
Start-Sleep -seconds 5 
}
我遇到的问题是访问被拒绝&WMI错误,脚本似乎尝试执行它应该执行的操作,但被阻止。我从DC运行,拥有完整的管理权限,没有防火墙,可以浏览测试VM的C$(测试环境中的1个DC和2个工作站)


看起来您的标题行以某种方式被读取为数据行,CSV文件的第一行中是否存储了标题“Oldname,Newname”?如果是这样,您应该从Import-Csv中删除-header子句。似乎没有为每台计算机执行一次添加计算机。foreach循环应该有一组大括号,跨越Rename Computer cmdlet和Add Computer cmdlet。您需要Rename Computer cmdlet上的-restart子句吗?您好,感谢您的提示,我已经将Rename comp*和Add Computer行放在一组括号中,从csv中删除了列标题名称,我想我离这有点近了。不确定是否需要重新启动子句,但大多数研究似乎都在示例中提供了它。我会编辑这篇文章,告诉你我现在在哪里…谢谢
Rename-Computer : Cannot establish the WMI connection to the computer 'bongo4' with the following error message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
At C:\SHARED\Batch_Rename_PC_and_Join.ps1:20 char:1
+ Rename-Computer -ComputerName $Computer.OldName -NewName $Computer.Ne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (bongo4:String) [Rename-Computer], InvalidOperationException
    + FullyQualifiedErrorId : RenameComputerException,Microsoft.PowerShell.Commands.RenameComputerCommand
 
Add-Computer : Cannot establish the WMI connection to the computer 'bongo4' with the following error message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
At C:\SHARED\Batch_Rename_PC_and_Join.ps1:21 char:1
+ Add-Computer -ComputerName $Computer.OldName -Domain 'ICTMBTST.local' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (bongo4:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : AddComputerException,Microsoft.PowerShell.Commands.AddComputerCommand
 
Rename-Computer : Cannot establish the WMI connection to the computer 'bongo3' with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).
At C:\SHARED\Batch_Rename_PC_and_Join.ps1:20 char:1
+ Rename-Computer -ComputerName $Computer.OldName -NewName $Computer.Ne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (bongo3:String) [Rename-Computer], InvalidOperationException
    + FullyQualifiedErrorId : RenameComputerException,Microsoft.PowerShell.Commands.RenameComputerCommand
 
Add-Computer : Cannot establish the WMI connection to the computer 'bongo3' with the following error message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
At C:\SHARED\Batch_Rename_PC_and_Join.ps1:21 char:1
+ Add-Computer -ComputerName $Computer.OldName -Domain 'ICTMBTST.local' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (bongo3:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : AddComputerException,Microsoft.PowerShell.Commands.AddComputerCommand