# SSH connection with PowerShell and Putty

**URL:** <https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745>\
**Category:** PowerShell Help\
**Created:** [August 10, 2023, 12:47pm UTC](https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745 "2023-08-10T12:47:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hethkleff](https://avatars.discourse-cdn.com/v4/letter/h/f1d935/32.png) [@hethkleff](https://forums.powershell.org/u/hethkleff)\
**Post date:** [August 10, 2023, 12:47pm UTC](https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745/1 "2023-08-10T12:47:23Z")

</div>

Hello

I am opening an SSH session from PowerShell by using plink.

```auto
&($plinkpath + "plink.exe") -pw $password $username@$servername -m $myscript
```

The problem is I am struggling to get a value of a variable from this session to use it for the my powershell script.

Any help please ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [August 11, 2023, 2:34pm UTC](https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745/2 "2023-08-11T14:34:01Z")

</div>

Hi hethkelff, welcome to the forum! 👋

> [@hethkleff](#):
>
> The problem is I am struggling to get a value of a variable from this session to use it for the my powershell script.

I’m afraid I am unable to discern what you mean by this. Do you mean there is a variable inside the session and you want to pull it out? If so, sounds like you just need to output the contents of the variable in the session and that will be the output of the powershell command.

Either way, can you please clarify/illustrate what you mean by this?

---

<div class="post-metadata">

**Author:** ![hethkleff](https://avatars.discourse-cdn.com/v4/letter/h/f1d935/32.png) [@hethkleff](https://forums.powershell.org/u/hethkleff)\
**Post date:** [August 11, 2023, 5:36pm UTC](https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745/3 "2023-08-11T17:36:41Z")

</div>

Hello krzydoug,

Thanks for this reply.  
I found the solution today and it’s not a complicated one actually.  
I used Invoke-Command like this:

$row\_data = Invoke-Command -ScriptBlock { scriptbolck…}

and then I got arguments of $row\_data: $row\_data[0]…

Best regards;

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/ssh-connection-with-powershell-and-putty/22745/4 "2024-05-16T20:14:42Z")

</div>

Closed on May 16, 2024, 8:14pm UTC


