我有一个包含无限循环的 powershell 脚本。我想使用 NSSM https://nssm.cc/description创建一个服务 但是一旦我在脚本中执行了一些过程,该服务就无法工作。这就是我创建服务的方式。
$NSSMPath = (Get-Command "D:\SERVICE\nssm-2.24\win64\nssm.exe").Source
$NameService = "TestService"
$PoshPath = (Get-Command powershell.exe).Source
$PoshScriptPath = "D:\SERVICE\TestService.ps1"
$arg = '-ExecutionPolicy Bypass -NoProfile -File "{0}"' -f $PoshScriptPath
& $NSSMPath install $NameService $PoshPath $args
Start-Service $NameService
Get-Service $NameService
这是 powersehll 脚本。
for(;;)
{
Start-Transcript -Path "D:\SERVICE\logfile.txt"
Stop-Transcript
}
有了这个 scipt,服务就可以工作了。我可以看到 logfile.txt。但是一旦我在这样的循环内部进行了一些处理
for(;;)
{
Start-Transcript -Path "D:\SERVICE\logfile.txt"
#add acnd check - will it work or not...
if(Test-Path -Path "D:\SERVICE\*.txt")
{
Get-ChildItem -Path "D:\SERVICE\*.txt" | Rename-Item -NewName {[System.IO.Path]::ChangeExtension($_.Name, ".csv")}
}
Stop-Transcript
}
服务正在运行,但脚本不工作,logfile.txt 不存在。
任何人都可以帮助我。谢谢