![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 thistopic 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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) 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 Specs![]() |
| | #6 (permalink) |
| | 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) >> > > 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 Specs![]() |
![]() |
| 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 | |||