Author Posts

October 23, 2014 at 5:51 am

Hello guys
please tel me the truth, where is my fault
I was trying to archive a few files simultaniously in such way

(pre)
#alias
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

#archive source files to volumes 1GB and save 7zfiles to temp folder
workflow Archive-Files {
$folder =dir $sourceFolder
# The files are processed in parallel.
foreach -parallel ($file in $folder)
{
sequence {
$Path=$file.FullName
$fileName=$file.Name
$basename=$file.Basename
$zippedFileName="$basename"+".7z"
$fullPathZippedFile=$tempZipFolder+$zippedFileName
sz a $fullPathZippedFile $Path -v1000M
}
}
}(/pre)

and it hangs forever(( no error no results. nothing

please help me

October 23, 2014 at 6:06 am

The sz command is being run in an implicit InlineScript activity. It doesn't have access to any of the variables and is probably prompting for something.

October 23, 2014 at 6:12 am

Dear Don

Please advise what do I need to change to get results
Do I need
InlineScript{sz a $fullPathZippedFile $Path -v1000M}

or do i need to use sz command without any $variable ?

or alias was set out of workflow scope?
Regards

October 23, 2014 at 7:04 am

Thanks you for responses MSDN has shown me the root cause

"
Variables in InlineScript

By default, the variables that are defined in a workflow are not visible to the commands in the InlineScript script block. To make workflow variables visible to the InlineScript, use the $Using scope modifier.
The following example shows how to make the values of top-level workflow variables available to the commands in an inlineScript script block."

Best regards
Yegor

October 23, 2014 at 7:50 am

I don't use workflows much, so I had to fiddle with this a bit. Here's what appears to work for me in testing. (I don't actually have 7-zip installed on this computer, so I just launched cmd.exe /c and echo'ed some text out to the .7z files as a test.)

$sourceFolder = 'C:\Source'
$tempZipFolder = 'C:\Source\Temp\'

#archive source files to volumes 1GB and save 7zfiles to temp folder
workflow Archive-Files {
    param (
        [string] $SourceFolder,
        [string] $ZipFolder
    )

    $folder = dir $SourceFolder
    # The files are processed in parallel.
    foreach -parallel ($file in $folder)
    {
        InlineScript {
            $Path=$using:file.FullName
            $fileName=$using:file.Name
            $basename=$using:file.Basename
            $zippedFileName="$basename"+".7z"
            $fullPathZippedFile= Join-Path $using:ZipFolder $zippedFileName
            & "$env:ProgramFiles\7-Zip\7z.exe" a $fullPathZippedFile $Path -v1000M
        }
    }
}

Archive-Files -SourceFolder $sourceFolder -ZipFolder $tempZipFolder

October 23, 2014 at 7:53 am

$using: was my gap
thanks a lot Dave
Also I have found this info about scopes within workflows on MSDN site

Thanks for your help