gpt4 book ai didi

Powershell 豪华 ssh : How to store results of Invoke-SSHCommand?

转载 作者:行者123 更新时间:2023-12-02 13:46:59 25 4
gpt4 key购买 nike

关闭连接后,如何存储 Invoke-SSHCommand 的结果以供使用?

我尝试了两种不同的方法:

#method 1
$result = Invoke-SSHCommand -Index 0 -Command "ls /somepath"

#method 2
Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable $result

两种方法后变量 $result 为空

最佳答案

这对我很有效:

# Create SSH Session
$ssh = New-SSHSession -ComputerName $PC01 -Credential $credential -AcceptKey 1

# Invoke SSH command and capture output as string (you can return the full object if you like, I just needed the string Out)
$ret = $(Invoke-SSHCommand -SSHSession $ssh -Command "racadm getconfig -g cfgUserAdmin -i 2").Output

# return object is a String - if you want it as an array of strings for each row returned
$ret = $ret.split("`n")

关于Powershell 豪华 ssh : How to store results of Invoke-SSHCommand?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41767454/

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