脚本在ISE中运行良好但从命令提示符失败

时间:2015-06-10 15:13:11

标签: powershell command-prompt

我有以下脚本:

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

最大的限制是脚本必须是单行的。

0 个答案:

没有答案