gpt4 book ai didi

使用调用运算符并传递自定义凭据的 Powershell 启动过程

转载 作者:行者123 更新时间:2023-12-04 01:43:05 26 4
gpt4 key购买 nike

我正在尝试使用 Octopus 部署执行 DbUp 应用程序。

说明说使用这个简单的脚本:

& .\DbUp.exe | Write-Host

但问题是我找不到传递自定义凭据来处理启动的方法。我尝试直接使用 Process 对象:
"DbUp Deployment Script starting." | Write-Host
$pinfo.Username = $OctopusParameters['serviceCustomAccountName']
$pinfo.Domain = "DOMAIN"
$pinfo.Password = (ConvertTo-SecureString -String $OctopusParameters['serviceCustomAccountPassword'] -AsPlainText -Force)
$pinfo.FileName = "C:\DbUp.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = ""
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start()
$p.WaitForExit()
$p.StandardOutput.ReadToEnd() | Write-Host
$p.StandardError.ReadToEnd() | Write-Host
"DbUp Deployment Script finished." | Write-Host

但是这种方法的结果是没有将 StandardOutput 传递给 Octopus 日志:
DbUp Deployment Script starting.
True
DbUp Deployment Script finished.

它似乎根本不执行 DbUp.exe,因为没有对数据库应用任何更改。

有没有办法使用调用运算符 (& .\DbUp.exe) 并传递自定义凭据来启动进程?如果不是,八达通不选择输出表单控制台应用程序的原因可能是什么?

最佳答案

powershell 用户上下文与运行触手服务的用户相关联,因此该服务可以是 admin 并具有 db 连接权限。与 start-process 一起使用的 -NoNewWindow 标志应该将输出重定向到同一个 session 。

关于使用调用运算符并传递自定义凭据的 Powershell 启动过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34222305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com