我有以下脚本:
Add-Computer -DomainName ("a.b.c.d") -Credential (New-Object System.Management.Automation.PsCredential("a.b.c.d\abcdadmin", (ConvertTo-SecureString "1234qwer" -AsPlainText -Force)))
显然域名不是'a.b.c.d',但它遵循这一点。它没有特殊的字符或任何会让我相信它会导致问题的东西。从ISE输出:
Add-Computer : Cannot add computer '<removed>' to domain 'a.b.c.d' because it is already in
that domain.
At line:1 char:1
+ Add-Computer -DomainName ("a.b.c.d") -Credential (New-Object System. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (20012UA95009JZ:String) [Add-Computer], InvalidOperationExce
ption
+ FullyQualifiedErrorId : AddComputerToSameDomain,Microsoft.PowerShell.Commands.AddComputerCommand
所以它在ISE中运行良好(除了它已经在域中),但是命令提示符说不然:
At line:1 char:143
+ ... fl.us\abcdadmin, (ConvertTo-SecureString 1234qwer -AsPlainText -Force)))
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : MissingArgument
最大的限制是脚本必须是单行的。