Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - start-psjob

Reply
 
Old 01-22-2008   #1 (permalink)
Robin Moffatt


 
 

start-psjob

Hi,

I'm trying to get background jobs to work, and struggling!

(I think part of the problem is that I don't understand in depth the
syntactical nicities of PS - single quoting/double quoting/ampersand/
etc - I know enough to get my scripts to work, but normally by brute
force so if anyone can recommend a detailed explanation on this
topic I'd appreciate it.)

Anyway, to my problem:

start-psjob "'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1 'c:
\temp' 0 1"

starts a job, but the job then fails with the error:

Unexpected token 'SERVER\INSTANCE' in expression or statement.

I'm pretty sure PS isn't happy with how I'm quoting various
parameters, but I don't know how to fix this.

Can anyone point out where I'm going wrong please?
Also, is there any way I can see how PS is going to parse a start-
job's command, without executing it? I.e. so I can look at what's
being passed to the command to hopefully spot syntax errors before the
job gets run.

TIA,
moff.

My System SpecsSystem Spec
Old 01-22-2008   #2 (permalink)
Joel (Jaykul) Bennett


 
 

Re: start-psjob

On Jan 22, 1:36 pm, Robin Moffatt <robin.moff...@xxxxxx> wrote:
Quote:

> Hi,
>
> I'm trying to get background jobs to work, and struggling!
>
> (I think part of the problem is that I don't understand in depth the
> syntactical nicities of PS - single quoting/double quoting/ampersand/
> etc - I know enough to get my scripts to work, but normally by brute
> force so if anyone can recommend a detailed explanation on this
> topic I'd appreciate it.)
>
> Anyway, to my problem:
>
> start-psjob "'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1 'c:
> \temp' 0 1"
>
> starts a job, but the job then fails with the error:
>
> Unexpected token 'SERVER\INSTANCE' in expression or statement.
>
> I'm pretty sure PS isn't happy with how I'm quoting various
> parameters, but I don't know how to fix this.
>
> Can anyone point out where I'm going wrong please?
> Also, is there any way I can see how PS is going to parse a start-
> job's command, without executing it? I.e. so I can look at what's
> being passed to the command to hopefully spot syntax errors before the
> job gets run.
>
> TIA,
> moff.


The problem is that you're quoting the script -- and strings aren't
executable. Try using the invoke "&" as in example 4 of the start-
psjob detailed help ...

start-psjob "& 'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1
'c:\temp' 0 1"

(I think that's all you need, but I don't have a PC I can run it on at
the moment)
My System SpecsSystem Spec
Old 01-23-2008   #3 (permalink)
RichS


 
 

Re: start-psjob

I've done some examples of using back ground jobs here

http://richardsiddaway.spaces.live.c...3E96!924.entry

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Joel (Jaykul) Bennett" wrote:
Quote:

> On Jan 22, 1:36 pm, Robin Moffatt <robin.moff...@xxxxxx> wrote:
Quote:

> > Hi,
> >
> > I'm trying to get background jobs to work, and struggling!
> >
> > (I think part of the problem is that I don't understand in depth the
> > syntactical nicities of PS - single quoting/double quoting/ampersand/
> > etc - I know enough to get my scripts to work, but normally by brute
> > force so if anyone can recommend a detailed explanation on this
> > topic I'd appreciate it.)
> >
> > Anyway, to my problem:
> >
> > start-psjob "'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1 'c:
> > \temp' 0 1"
> >
> > starts a job, but the job then fails with the error:
> >
> > Unexpected token 'SERVER\INSTANCE' in expression or statement.
> >
> > I'm pretty sure PS isn't happy with how I'm quoting various
> > parameters, but I don't know how to fix this.
> >
> > Can anyone point out where I'm going wrong please?
> > Also, is there any way I can see how PS is going to parse a start-
> > job's command, without executing it? I.e. so I can look at what's
> > being passed to the command to hopefully spot syntax errors before the
> > job gets run.
> >
> > TIA,
> > moff.
>
>
>
> The problem is that you're quoting the script -- and strings aren't
> executable. Try using the invoke "&" as in example 4 of the start-
> psjob detailed help ...
>
> start-psjob "& 'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1
> 'c:\temp' 0 1"
>
> (I think that's all you need, but I don't have a PC I can run it on at
> the moment)
>
My System SpecsSystem Spec
Old 01-23-2008   #4 (permalink)
Robin Moffatt


 
 

Re: start-psjob

Hi Richard,
Thanks for your reply. I had a look on your webpage, but couldn't see
anything that addressed my queries?

Thanks, moff.

On Jan 23, 8:29 am, RichS <Ri...@xxxxxx> wrote:
Quote:

> I've done some examples of using back ground jobs here
>
> http://richardsiddaway.spaces.live.c...6A74CF3E96!924....
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
> "Joel (Jaykul) Bennett" wrote:
Quote:

> > On Jan 22, 1:36 pm, Robin Moffatt <robin.moff...@xxxxxx> wrote:
Quote:

> > > Hi,
>
Quote:
Quote:

> > > I'm trying to get background jobs to work, and struggling!
>
Quote:
Quote:

> > > (I think part of the problem is that I don't understand in depth the
> > > syntactical nicities of PS - single quoting/double quoting/ampersand/
> > > etc - I know enough to get my scripts to work, but normally by brute
> > > force so if anyone can recommend a detailed explanation on this
> > > topic I'd appreciate it.)
>
Quote:
Quote:

> > > Anyway, to my problem:
>
Quote:
Quote:

> > > start-psjob "'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1 'c:
> > > \temp' 0 1"
>
Quote:
Quote:

> > > starts a job, but the job then fails with the error:
>
Quote:
Quote:

> > > Unexpected token 'SERVER\INSTANCE' in expression or statement.
>
Quote:
Quote:

> > > I'm pretty sure PS isn't happy with how I'm quoting various
> > > parameters, but I don't know how to fix this.
>
Quote:
Quote:

> > > Can anyone point out where I'm going wrong please?
> > > Also, is there any way I can see how PS is going to parse a start-
> > > job's command, without executing it? I.e. so I can look at what's
> > > being passed to the command to hopefully spot syntax errors before the
> > > job gets run.
>
Quote:
Quote:

> > > TIA,
> > > moff.
>
Quote:

> > The problem is that you're quoting the script -- and strings aren't
> > executable. Try using the invoke "&" as in example 4 of the start-
> > psjob detailed help ...
>
Quote:

> > start-psjob "& 'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1
> > 'c:\temp' 0 1"
>
Quote:

> > (I think that's all you need, but I don't have a PC I can run it on at
> > the moment)
My System SpecsSystem Spec
Old 01-24-2008   #5 (permalink)
Robin Moffatt


 
 

Re: start-psjob

On Jan 22, 6:43 pm, "Joel (Jaykul) Bennett" <Jay...@xxxxxx>
wrote:
Quote:

>
> The problem is that you're quoting the script -- and strings aren't
> executable. Try using the invoke "&" as in example 4 of the start-
> psjob detailed help ...
>
> start-psjob "& 'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1
> 'c:\temp' 0 1"
>
> (I think that's all you need, but I don't have a PC I can run it on at
> the moment)
Thanks for the reply Joel.

FWIW I got it working in the end like this (not sure what would happen
if i had spaces in my script path though)

start-psjob "c:\code\databases\myscript.ps1 'SERVER\INSTANCE' DB1 'c:
\temp' 0 1"
My System SpecsSystem Spec
Old 01-24-2008   #6 (permalink)
Shay Levi


 
 

Re: start-psjob

I copied your script into a ps1 file and it's working fine for me:

PS > Start-PSJob .\temp\sql.ps1

SessionId Name State HasMoreData Command
--------- ---- ----- ----------- -------
1 Running True .\temp\sql.ps1


Btw.. you got a space in "c: \temp"

If your scripts path conatins spaces, wrap it with single quotes:

start-psjob "'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1 'c:\temp'
0 1"


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> On Jan 22, 6:43 pm, "Joel (Jaykul) Bennett" <Jay...@xxxxxx>
> wrote:
>
Quote:

>> The problem is that you're quoting the script -- and strings aren't
>> executable. Try using the invoke "&" as in example 4 of the start-
>> psjob detailed help ...
>>
>> start-psjob "& 'c:\code\databases\myscript.ps1' 'SERVER\INSTANCE' DB1
>> 'c:\temp' 0 1"
>>
>> (I think that's all you need, but I don't have a PC I can run it on
>> at the moment)
>>
> Thanks for the reply Joel.
>
> FWIW I got it working in the end like this (not sure what would happen
> if i had spaces in my script path though)
>
> start-psjob "c:\code\databases\myscript.ps1 'SERVER\INSTANCE' DB1 'c:
> \temp' 0 1"
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Start-PSJob doesn't complete the backgroundjob PowerShell
start-psjob - user credentials PowerShell
PSJob+WinRM=Connection attempt failed. PowerShell
PSJob+WinRM=Connection attempt failed. PowerShell
psjob - Connection attempt failed. / Server execution failed PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46