0

我有一个 powershell 脚本来创建可在本地 Windows 10 PC 上运行的服务。下面工作正常。

$nssm = (Get-Command nssm).Source
$serviceName = 'ImageResize'
$powershell = (Get-Command powershell).Source
$scriptPath = 'C:\ImageTest\Scripts\current\ResizeImage.ps1'
$arguments = '-ExecutionPolicy Bypass -NoProfile -File "{0}"' -f $scriptPath
& $nssm install $serviceName $powershell $arguments
& $nssm status $serviceName
Start-Service $serviceName
Get-Service $serviceName

在 Windows 2012 服务器上尝试相同的脚本时出现错误。成绩单显示如下:

The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
At line:10 char:3
+ & $nssm install $serviceName $powershell $arguments
+   ~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadExpression

我还在事件查看器中找到了以下内容:

应用

Failed to start service imagetest.  Program C:\ImageResizeScript\ResizeImage.ps1 couldn't be launched. CreateProcess()` failed: imagetest is not a valid Win32 application.

系统

The system cannot find the specified path
4

0 回答 0