在Active Directory CN中运行powershell命令时,一个或多个计算机名无效
因此,我正在学习powershell,目前希望在本地内置管理员帐户上设置密码。我可以在OU测试组中运行以下命令,它可以正常工作在Active Directory CN中运行powershell命令时,一个或多个计算机名无效,powershell,active-directory,Powershell,Active Directory,因此,我正在学习powershell,目前希望在本地内置管理员帐户上设置密码。我可以在OU测试组中运行以下命令,它可以正常工作 Invoke-Command -ScriptBlock {net user administrator "R@nd0mP@ssw0rd!@#"} -ComputerName (Get-ADComputer -SearchBase "OU=Test,DC=fqdn,DC=local" -Filter * | Select-Object -Expand Name) *>
Invoke-Command -ScriptBlock {net user administrator "R@nd0mP@ssw0rd!@#"} -ComputerName (Get-ADComputer -SearchBase "OU=Test,DC=fqdn,DC=local" -Filter * | Select-Object -Expand Name) *> "C:\users\user\desktop\WinRMAdminPWSet.txt"
如果在包含计算机的CN上运行此命令,则会出现以下错误
Invoke-Command -ScriptBlock {net user administrator "R@nd0mP@ssw0rd!"} -ComputerName (Get-ADComputer -SearchBase "CN=Computers,DC=fqdn,DC=local" -Filter * | Select-Object -Expand Name) *> "C:\users\user\desktop\WinRMAdminPWSet.txt"
Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
At line:1 char:1
+ Invoke-Command -ScriptBlock {net user administrator "R@nd0mP@ssw0rd! ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException
+ FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand
我觉得在OU和CN上运行此命令应该没有什么区别,但似乎是这样的?我会尝试检查返回的计算机名是否正常:$computerNames=Get-ADComputer-SearchBase“CN=Computers,DC=fqdn,DC=local”-Filter*| Select Object-Expand Name Write Host“计算机名为:$computerNames”如果您只使用search base执行Get-ADComputer操作,那么容器会得到结果吗?如果是这样,您可以导出计算机列表并运行foreach命令以获取所需信息。我会尝试检查作为健全性检查返回的计算机名:$computerNames=Get-ADComputer-SearchBase”CN=Computers,DC=fqdn,DC=local“-Filter*| Select Object-展开Name Write Host“computer names are:$computerNames”如果您仅使用搜索库执行Get-ADComputer操作,那么容器是否获得结果?如果是这样,您可以导出计算机列表并运行foreach命令以获取所需信息。