如果我尝试运行下面的脚本,我会收到WMI访问被拒绝错误。但是,如果我使用相同的凭据在命令行运行该命令,它会顺利通过。请解释脚本有什么问题。
这在命令提示符下正常工作:
Rename-Computer -ComputerName U1004062-TLL-A -NewName U1004062-TLL-B -LocalCredential ten \ LocalAdmin -DomainCredential ten \ DomainAdmin -force -passthru -restart
使用相同的凭据不起作用。
Import-Module activedirectory
$list = Import-csv C:\temp\machine.csv -Header oldcomputer, newcomputer
$local = "domain"
$userlocal = "LocalAdmin"
#Don't edit below this point
$passwordlocal = Read-Host -Prompt "Enter password for $userlocal" -AsSecureString
$usernamelocal = "$local\$userlocal"
$credentiallocal = New-Object System.Management.Automation.PSCredential($usernamelocal, $passwordlocal)
$domain = "ten"
$user = "domainadmin"
#Don't edit below this point
$password = Read-Host -Prompt "Enter password for $user" -AsSecureString
$username = "$domain\$user"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
foreach ($machine in $list)
{Rename-Computer -ComputerName $machine.oldcomputer -NewName $machine.newcomputer -LocalCredential $credentiallocal -DomainCredential $credential -Force -passthru -Restart}
答案 0 :(得分:0)
我确实弄明白了这个问题。该公司使用ARS,您必须通过ARS控制台和代理服务运行所有内容,以便在AD中执行任何操作。