Reputation: 16236
I would like to change this one long line into multiple lines in the cmd
script.
powershell.exe -Command "Send-MailMessage -To '[email protected]' -From '[email protected]' -Subject 'Standard Extract Request' -SmtpServer 'mail.company.com' -Attachment 'file.txt'"
Using the cmd
line continuation character, "^", does not work. Likewise, using the powershell
line continuation character, "`", also fails.
THIS DOES NOT WORK
powershell.exe -Command "Send-MailMessage ^
-To '[email protected]' ^
-From '[email protected]' &
-Subject 'Standard Extract Request' ^
-SmtpServer 'mail.company.com' ^
-Attachment 'file.txt'"
Upvotes: 1
Views: 1019
Reputation: 86
Just remove the " around the Command and change the & by a ^test, like this:
powershell.exe -Command Send-MailMessage ^
-To '[email protected]' ^
-From '[email protected]' ^
-Subject 'Standard Extract Request' ^
-SmtpServer 'mail.company.com' ^
-Attachment 'file.txt'
Upvotes: 2
Reputation: 200293
Don't do that. If you want to wrap PowerShell statements, put them in a .ps1 file:
Send-MailMessage `
-To '[email protected]' `
-From '[email protected]' `
-Subject 'Standard Extract Request' `
-SmtpServer 'mail.company.com' `
-Attachment 'file.txt'
and run that file:
powershell.exe -File "C:\path\to\your.ps1"
Upvotes: 0