Error "TerminatorExpectedAtEndOfString" when execute a powershell code from a batch file?

Microsoft Windows
Post Reply
Hackoo
Posts: 5
Joined: 2021-Oct-17, 6:40 pm

Error "TerminatorExpectedAtEndOfString" when execute a powershell code from a batch file?

Post by Hackoo »

Hi ;)
I want to execute a powershell code with a batch file to take a screenshot from my desktop that i found it here
Take a Screenshot of a User’s Desktop with PowerShell

So,When i execute it as powershell script it works without any error and works for me 5/5 but when i take it as batch file like this i got this type of error that i don't know how to debug it correctly ?

Error :TerminatorExpectedAtEndOfString

So if someone can explain me why and where this error comes from ?

Here is my batch code :

Code: Select all

@echo off
Title Get a ScreenShot with Batch and Powershell
Call :ScreenShot
pause
::----------------------------------------------------------------------------------------------------------------------------
:ScreenShot
Powershell ^
$Path = "E:\ScreenCapture\";^
Add-Type -AssemblyName System.Windows.Forms;^
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds;^
$image = New-Object System.Drawing.Bitmap($screen.Width, $screen.Height);^
$graphic = [System.Drawing.Graphics]::FromImage($image);^
$point = New-Object System.Drawing.Point(0,0);^
$graphic.CopyFromScreen($point, $point, $image.Size);^
$cursorBounds = New-Object System.Drawing.Rectangle([System.Windows.Forms.Cursor]::Position,[System.Windows.Forms.Cursor]::Current.Size);^
[System.Windows.Forms.Cursors]::Default.Draw($graphic, $cursorBounds);^
$FileName = (Get-Date -F dd-MM-yyyy_HH_mm_ss)+".jpg";^
$FilePath = $Path$FileName;^
$FormatJPEG = [System.Drawing.Imaging.ImageFormat]::jpeg;^
$image.Save($FilePath,$FormatJPEG)
Exit /B
::----------------------------------------------------------------------------------------------------------------------------
User avatar
Simon Sheppard
Posts: 190
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Error "TerminatorExpectedAtEndOfString" when execute a powershell code from a batch file?

Post by Simon Sheppard »

See here
https://ss64.com/ps/powershell.html#longfilenames

if you are calling PowerShell from a CMD batch file and the command contains quotation marks, they must be escaped: " becomes \"
Hackoo
Posts: 5
Joined: 2021-Oct-17, 6:40 pm

Re: Error "TerminatorExpectedAtEndOfString" when execute a powershell code from a batch file?

Post by Hackoo »

Simon Sheppard wrote: 2021-Oct-29, 2:57 pm See here
https://ss64.com/ps/powershell.html#longfilenames
if you are calling PowerShell from a CMD batch file and the command contains quotation marks, they must be escaped: " becomes \"
Thank you for your reply and i just have solved this problem here
Post Reply