Rectangle 27 0

shell save FTP request to string Invoke Expression to DOS?

Okay, I see that, but what I'm wondering is why do you want to invoke cmd from PowerShell in order to create a text file? Why not just run "user`npass`npwd`ncd DIR`nbinary`nget spec`nbye" > test.ftp at the PowerShell prompt? In fact, is there any reason you want to use cmd at all? ftp isn't a native cmd command, it's a standalone .exe bundled with Windows (in the system32 directory) and can be invoked directly from PowerShell. Or you might find (echo user pass pwd 'cd DIR' binary 'get spec' bye) -join "`n" more readable.

Place the contents of your here-string in a .bat file, then run cmd /c <path to batch file>. You don't even need Invoke-Expression. You can run cmd directly as a command from a PowerShell prompt.

cmd /c can't take a multi-line string as an argument. If you want to execute multiple statements, you need to separate them with the command separator character &. However, what you're doing here is essentially trying to pass it a batch file in a string argument.

thanks for chiming in, but in my first sentence i wrote I want to send a FTP request ... without pointing it to a saved script. I ended up doing what you suggested just to have a quick-n-dirty solution, but i am still looking for a way to do it without having to point to a file from within the POSH script.