Skip to content

Question about Invoke-Plaster and -Passthru #234

Description

@LaurentDardenne

I use the latest build, and i test the passthru parameter of Invoke-Plaster :

$Result=invoke-plaster "C:\Program Files\WindowsPowerShell\Modules\plaster\1.0.2\Templates\NewPowerShellScriptModule\" -DestinationPath C:\temp\TestManifest -PassThru
$Result

The result is correct :

Destination path: C:\temp\TestManifest


TemplatePath    : C:\Program Files\WindowsPowerShell\Modules\plaster\1.0.2\Templates\NewPowerShellScriptModule\
DestinationPath : C:\temp\TestManifest
Success         : True
TemplateType    : Project
CreatedFiles    : {C:\temp\TestManifest\test.psd1, C:\temp\TestManifest\test.psm1}
UpdatedFiles    : {}
MissingModules  : {}
OpenFiles       : {C:\temp\TestManifest\test.psd1, C:\temp\TestManifest\test.psm1}

Now i lock the test.psm1 file and call Invoke-Plaster again :

Function Lock-File{
  param([string] $Path)

  New-Object System.IO.FileStream($Path, 
                                  [System.IO.FileMode]::Open, 
                                  [System.IO.FileAccess]::ReadWrite, 
                                  [System.IO.FileShare]::None)
} #Lock-File

Remove-Variable Result
.{
 try {
    $Filename="C:\temp\TestManifest\test.psm1"
    $TestLockFile= Lock-File $FileName
    $Result=invoke-plaster "C:\Program Files\WindowsPowerShell\Modules\plaster\1.0.2\Templates\NewPowerShellScriptModule\" -DestinationPath C:\temp\TestManifest -PassThru
  } finally {
   $TestLockFile.Close()
  }
}

#... same informations
Scaffolding your PowerShell Module...

Identical test.psd1
Get-FileHash : The file 'C:\temp\TestManifest\test.psm1' cannot be read: Le processus ne peut pas accéder au fichier
'C:\temp\TestManifest\test.psm1', car il est en cours d'utilisation par un autre processus.
At C:\Program Files\WindowsPowerShell\Modules\plaster\1.0.2\InvokePlaster.ps1:873 char:23
+ ...      $hash2 = (Get-FileHash -LiteralPath $path2 -Algorithm SHA1).Hash
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (C:\temp\TestManifest\test.psm1:PSObject) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FileReadError,Get-FileHash

 Conflict test.psm1

Plaster file conflict
Overwrite C:\temp\TestManifest\test.psm1
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
Copy-Item : Le processus ne peut pas accéder au fichier 'C:\temp\TestManifest\test.psm1', car il est en cours
d'utilisation par un autre processus.
At C:\Program Files\WindowsPowerShell\Modules\plaster\1.0.2\InvokePlaster.ps1:1002 char:21
+ ...             Copy-Item -LiteralPath $DstPath -Destination $backupFilen ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

The Result variable is not created.

Is the correct behavior in this case or all exceptions must trapped when -Passtrhu is set ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions