【问题标题】:New-PSSession to Linux host is frozen when run under SYSTEM Account在 SYSTEM 帐户下运行时,Linux 主机的新 PSSession 被冻结
【发布时间】:2021-04-14 22:32:06
【问题描述】:

我尝试通过 Jenkins 在系统帐户下运行 Powershell 脚本。

$DebugPreference = 'Continue'
$dt=get-date -Format "MM-dd-yyyy-HH-mm-ss-fff"
Start-Transcript -Path "C:\install\transcript-$dt.txt"
dir env:
$cmdline = $((Get-CimInstance win32_process -Filter "ProcessID=$PID" | ? { $_.processname -eq "pwsh.exe" }).commandline)
if($cmdline -like "*pwsh.exe*")
{
    write-host "Powershel 7 continue" 
    Write-Host "Before Start-session"
    $s = New-PSSession -HostName ip -UserName user -verbose  -KeyFilePath C:\.ssh\id_rsa
    Write-Host "After Start-session"
  
}else{
    Start-Process pwsh.exe -Wait -PassThru  -ArgumentList "-NonInteractive -ExecutionPolicy Bypass -File $($MyInvocation.MyCommand.Definition)"
}    
stop-transcript

   

我的问题是写入主机“启动会话后”从未达到。

第一个 Start-Transcript 显示,该脚本再次使用 pwsh.exe 启动

第二个 Start-Transcript 显示在 Start-session 之前的输出。

之后,没有任何内容添加到 Transcript 中,并且进程继续运行。

脚本在管理员帐户下运行时运行良好。

如何调试?

【问题讨论】:

  • 您可以使用-Debug,但是我无法理解您的意思。怎么永远达不到?
  • 它需要无限长的时间。它很简单,只是在执行 New-PSSession 时挂起
  • 您可以将其用作作业,因此它不会等待它终止。你是如何使用它的?我没有看到正在使用的会话

标签: powershell


【解决方案1】:

问题在于 SSH 指纹不受信任。 当我通过命令行而不是直接通过 Jenkins 运行脚本时,我得到了以下输出: The authenticity of host 'ip (ip)' can't be established. ECDSA key fingerprint is SHA256:gQv8WE8G04RhfNNX7pRQjVX0lPj3jNZ4JTPIDNEIGHk. Are you sure you want to continue connecting (yes/no)?

在我回答“是”之后,一切正常。 Jenkings Job 现在是两个人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多