none
start sleep script need understanding RRS feed

  • Question

  • $job = Start-Job {$i=0; $c=0; while (1) { 
    Write-Progress Activity "Step $i"; $i++; Start-Sleep -sec 1 }}
    while ($job.State -eq 'Running' -And $c -lt 5) {
    $c++;
    $progress=$job.ChildJobs[0].progress; 
    $progress | %{$_.StatusDescription}; 
    $progress.Clear(); Start-Sleep 1 }
    

    I have been trying to work around a script which waits for backup to complete and than executes the next block of code, but i could not do it with start-job and wait-job, i found the above code and pasted into my document and it worked, but as i am new to powershell i dont know what exactly this script is doing

    Wednesday, July 16, 2014 4:03 PM

Answers

  • i am using this zip script, 

    $path = $args[0]
    $files = $input

    write-output $path

    if (-not $path.EndsWith('.zip')) {$path += '.zip'}   

    if (-not (test-path $path)) { 
      set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 


    $ZipFile = (new-object -com shell.application).NameSpace($path) 
    $files | foreach {$zipfile.CopyHere($_.fullname)}  

    As noted repeatedly.  You cannot use the shell to zip files. It will not work for large collections of files.  It cannot be waited on.  The shell call is not intended to be used outside of explorer.  Use 7-Zip or another zip utility.

    Your problem cannot be solved by any normal means.


    ¯\_(ツ)_/¯

    Thursday, July 17, 2014 11:57 AM

All replies

  • Same problem and same issue.  What you are trying to do will not work because the process does not behave as expected.

    I recommend  contacting the vendor of your backup utility and asking them how to solve your issue.  If you are using shell zip to backup then you have to change to a command line zip program.

    The script you pasted just demos the progress bar which runs until a job completes.  It samples job output to increment the progress.  It won't help you.


    ¯\_(ツ)_/¯

    Wednesday, July 16, 2014 5:36 PM
  • By the way.  The script you posted appears to be just nonsense.  Forget about it.

    ¯\_(ツ)_/¯

    Wednesday, July 16, 2014 5:39 PM
  • i am using this zip script, 

    $path = $args[0]
    $files = $input

    write-output $path

    if (-not $path.EndsWith('.zip')) {$path += '.zip'}   

    if (-not (test-path $path)) { 
      set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 


    $ZipFile = (new-object -com shell.application).NameSpace($path) 
    $files | foreach {$zipfile.CopyHere($_.fullname)}  

    Thursday, July 17, 2014 8:27 AM
  • i am using this zip script, 

    $path = $args[0]
    $files = $input

    write-output $path

    if (-not $path.EndsWith('.zip')) {$path += '.zip'}   

    if (-not (test-path $path)) { 
      set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 


    $ZipFile = (new-object -com shell.application).NameSpace($path) 
    $files | foreach {$zipfile.CopyHere($_.fullname)}  

    As noted repeatedly.  You cannot use the shell to zip files. It will not work for large collections of files.  It cannot be waited on.  The shell call is not intended to be used outside of explorer.  Use 7-Zip or another zip utility.

    Your problem cannot be solved by any normal means.


    ¯\_(ツ)_/¯

    Thursday, July 17, 2014 11:57 AM
  • jrv is correct. The shell CopyHere method runs asynchronously and is not designed to be automated by script. You will not be able to automate this reliably in any way. Read this thread first:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/760ea95b-4c3e-4f48-a0f6-9d728d5580da/

    You will need to use another zip utility to do this.


    -- Bill Stewart [Bill_Stewart]

    Thursday, July 17, 2014 2:15 PM
    Moderator
  • With PowerShell V3 you can do this.

    PS C:\scripts> Add-Type -AssemblyName System.IO.Compression.FileSystem 
     PS C:\scripts> [System.IO.Compression.ZipFIle]::CreateFromDirectory("c:\scripts\","c:\temp2\scrips.zip") 
    PS C:\scripts> dir c:\temp2\scrips.zip 
    
    Directory: C:\temp2 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/24/2014 12:06 PM 8421644 scrips.zip
    



    ¯\_(ツ)_/¯






    • Edited by jrv Wednesday, September 24, 2014 4:09 PM
    Wednesday, September 24, 2014 4:06 PM
  • This is good. The point is to use these .NET objects, or an external zip utility, rather than trying to automate the shell objects. (The OP keeps starting new threads asking how to use the shell objects in PowerShell, and we keep saying, "don't do that.")

    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 24, 2014 4:25 PM
    Moderator