我可以右键单击DEC16.bat文件并运行。我无法将其包含在脚本中以便从闪存驱动器运行。 PowerShell脚本实质上是将一堆安装文件复制到客户机的计算机上。尝试使用runas运行.bat文件时出错使用PowerShell的管理员
Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.
PS H:\> $script = "\\xxxhsfmsl03\adap\Database\Install\AugKA\DEC16.bat"
PS H:\>
PS H:\> Start-Process powershell -Credential “xxx\xxxvis_desktop” -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'
Start-Process : This command cannot be run due to the error: The directory name is invalid.
At line:1 char:1
+ Start-Process powershell -Credential “xxx\xxxvis_desktop” -ArgumentList '-noprof ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
PS H:\> $script
\\xxxhsfmsl03\adap\Database\Install\AugKA\DEC16.bat
PS H:\>
(我已经插入的 “XXX” 的保护无辜者)
参数列表是引用单引号。因此$ script不会展开。使用双引号 – Matt
如果你从[这里]得到这段代码(http://stackoverflow.com/questions/15305696/running-a-bat-file-as-admin-from-powershell)我明白了。我看你昨天在那里留言。我还留下了一个指出错误。 – Matt