last day (15 days later) » 

10:48 AM
1
A: How to put a job on wait in powershell

NadeemTry $Job = Start-Job -ScriptBlock ..... Wait-Job -Id $Job.Id For the ScriptBlock error, try specifying the starting brace at the same line like: $Job = Start-Job -ScriptBlock { # Job code here }

 
where shall i specify the above code. in the backup script or in the main script which is calling the backup script]#
This is what i have written in my main scipt which is calling the backup script $Job = Start-Job -ScriptBlock {./Russia_Backup.ps1} Wait-Job -Id $Job.Id but its not creating the backup
 
Do you get any error.
 
No error message, its says job completed but it doesnot create the backup folder, i am going to modify the new script in my question if you can have a read,
 
Have you tried running your back up script without AsJob and checked if it works that way.
 
I am calling the above backup script from my main script using this line of code ./Russia_backup.Ps1
do you mean running the script without wait-job ???
 
10:48 AM
I meant out-zip file. Have you tried to run it separately to check if it works.
 
hi nadeem its saad
 
hi
try executing the file out-zip directly, not from inside your main script to check if that works
 
do you mean shall i copy the content of out-zip in the backup folder,,i am soo confused
this is my main script which is calling the backup script
$content = get-childitem 'C:\_Backups\121.Russia.V2'
$sortedContent = $content | Sort-Object LastWriteTime -Descending

# 1. LIST BACKUPS
write-host "This is the list of all the backups for 121.Russia.V3 :"

$count = 1
foreach ($item in $sortedContent)
{
#Edit: Now with auto-incrementing counter
Write-Host ("{0}: {1}" -f $count, $item.Name)
$count++
}
# 1. LIST BACKUPS


# 2.Take input from user
$itemNumber = Read-Host "Please select which backup you want to restore"
$confirmation = Read-Host "Are you Sure You Want To Proceed:"
 
just read your latest comment, so if you don't want
have a question
why are you using start-job at all
 
to be honest i dont know how to put a wait for my backup to finish
once backup gets finish than i want to delete admin and tablet,
 
10:55 AM
have you tried without Start-Job
 
if i dont use any start-job cmdlets than i get error of file locking
 
ahh okay
 
yes without start job i get file locking error because the backup script is trying to backup admin and tablet folder but at the same time my next block of code is deleteing the admin and tablet folder
if you have a look at my main script it will clarify everything..i am soo stuck at my job and unable to get this working,
 
just to check if you code is actually creating backup,
could you try after removing Start-Job and add the line Start-Sleep -Seconds 30 after the line where you are calling your backup file
 
have a lot of pressure to get this done
i can get this done straight away by putting start-sleep 30 in my main script after this line of code ./121.russia.local bakup.ps1 but my manager said dont use sleep
because sometimes we dont know how long the backup will take to fiinisg
finish
 
10:59 AM
yeah, that's right I just wanted to make sure that your script works with that
so there is something down to Start-Job wait
 
yea that way script is running perfect and creates proper backup and than deletes the folders and than restores them, but manager is not agreeing
 
of course that's not the right way to do it
that way it could break anytime
 
you are right, but i dont know how to get this done. it has been 2 days now
is it okay if i send you all 3 scripts ...,main ...backup ...zip
thanks alot that you are helping
 
well i got stuck to something similar and in my case Wait-Job did the trick
yeah would be good to have a look at the scripts you have
 
i suggested my manager to put read-host after ./backup line in main script ,,,that worked for me but he said he doesnt want to do it that way, what if user goes away and time will be waisted in waiting for user input to continue
can u give me your email and i am going to email you straight away
 
11:04 AM
nadeem_1359@yahoo.co.in
 
just sent you email
with all 3 scripts
 
okay, let me check
 
thanks
 
for some security reasons didn't received the ps1 files, could you please send the mail again after changing their extension to .txt
Also could you try this in the mean time
Wait-Job $job
Receive-Job $job
 
ok
just sent u email ,,,3 scripts in txt format
will it be possibe for you to modify the script please,
brother
i am going to pray...can i catch you when i come back
or if you can email me i will be back soon#
 
 
2 hours later…
1:03 PM
hi
 
1:58 PM
hi
 

  last day (15 days later) »