0

I want to automate a query that we run manually on networkShell putty by pasting a query from excel sheet into Putty. I have followed the steps :

  1. Open nsh.bat using PowerShell

    $wshell = New-Object -com WScript.Shell
    $wshell.Run("nsh.bat")
    
  2. After that login to putty using command sendkeys and normally press enter by using "sendkeys" only

  3. I have an Excel sheet where query is pasted in the sheet and I have created a com object of excel and to copy data from the excel sheet

    $Excel = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook = $Excel.Workbooks.Open("Path of excel sheet")
    $worksheet1 = $Workbook.worksheets.item(1)
    $worksheet1.activate()
    $Range = $worksheet1.Range("A1","A38")
    $Range.Copy()**
    
  4. Now I want to paste this copied data from excel into Putty(nsh.bat file we have opened) using PowerShell command. Manually we can click mouse right click to paste data into putty but I am unable to paste data using Powershell automatically as Mouse right click is not possible using PowerShell as I couldn't find anywhere. Please help if we can or any way to perform this task.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Chintu
  • 1
  • Then why not just save it to a file and read it back vs the C/P gymnastics you are trying. Just curious... Why would you believe you can't do Right_CLick with PS? [Sure you can, and other are several articles on the topic](https://duckduckgo.com/?q=%27powershell+right+click+mouse%27&t=h_&ia=web). So, I'd be curious what you looked for, but I still say, 'why do it at all?'. – postanote Jul 21 '22 at 04:47
  • Does this answer your question? [Automating command/script execution using PuTTY](https://stackoverflow.com/questions/39361444/automating-command-script-execution-using-putty) – Martin Prikryl Jul 26 '22 at 04:22

0 Answers0