0

I have the following PowerShell script Job that uses a ScriptBlock. I am trying to use the variable $pw1 but it does not seem to be using it correctly. How can I use variables in a ScriptBlock or a string?

Start-Job -ScriptBlock {Start-Process "C:\Users\Mark\Desktop\putty.exe" -argumentlist "-ssh Mark@192.168.1.3  -pw $pw1 -m C:\Users\Mark\Desktop\commands.txt -t" -passthru -Wait ;cmd.exe /c start cmd /k PSlist}
infused
  • 24,000
  • 13
  • 68
  • 78

1 Answers1

0

Not sure to fully understand your whole putty call, but if you want to put your password argument (-pw) which in the $pw1 variable of your calling script you should use the arguments :

Start-Job -ScriptBlock {Start-Process "C:\Users\Mark\Desktop\putty.exe" -argumentlist "-ssh Mark@192.168.1.3  -pw $args[0] -m C:\Users\Mark\Desktop\commands.txt -t" -passthru -Wait ;cmd.exe /c start cmd /k PSlist} -ArgumentList $pw1

$args[0] will contain the value of $pw1.

CB.
  • 58,865
  • 9
  • 159
  • 159
JPBlanc
  • 70,406
  • 17
  • 130
  • 175