PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Add PassThru parameter to New-PSScriptFileInfo

Open tmarvin-repay opened this issue 3 years ago • 4 comments

Summary of the new feature / enhancement

As a script writer I want to be able to use New-PSScriptFileInfo to generate a PSScriptInfo comment block, after I have already created a script, without being required to create a temporary file to satisfy the mandatory FilePath parameter.

Proposed technical implementation details (optional)

Add a PassThru switch parameter to New-PSScriptFileInfo as an alternate mandatory parameter to FilePath and write the PSScriptInfo to the output stream.

Example Usage:

PS C:\> New-PSScriptFileInfo -Description 'A Verbose  Description!' -PassThru
<#PSScriptInfo

.VERSION 1.0.0.0

.GUID 1cf87ca2-f069-414f-a554-fc691eaf52fa

.AUTHOR {username}

.COMPANYNAME

.COPYRIGHT

.TAGS

.LICENSEURI

.PROJECTURI

.ICONURI

.EXTERNALMODULEDEPENDENCIES

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES


.PRIVATEDATA


#>
<#

.DESCRIPTION
A Verbose  Description!

#>
PS C:\> 

tmarvin-repay avatar Jul 28 '22 23:07 tmarvin-repay

This would be an easy thing for us to add in but, just out of curiosity, are you then doing anything with this output?

alerickson avatar Jul 29 '22 20:07 alerickson

In my personal usecase I would just emit it to the host console. But I could see it being used to automatically add a default scriptinfo header as part of the build process for scripts that were added to source control without one.

tmarvin-repay avatar Jul 29 '22 20:07 tmarvin-repay

To clarify, the ask would be to pass thru the contents of the scriptfile rather than the scriptfileinfo object

SydneyhSmith avatar Aug 04 '22 18:08 SydneyhSmith

A PassThru parameter isn't needed in this case. If I'm reading the OP request correctly it is to send the script info comment block string to the pipeline so that it can be used directly without having to write it to a file and then read it as the current cmdlet dictates.

To meet this request the behavior should be as follows.

  • Remove FilePath as a required parameter
  • If FilePath is not passed then it will output the PSScriptInfo comment block to the pipeline
  • If FilePath is passed then the file will be created with the comment block

Once that behavior has been completed then a PassThru parameter returning a PSScriptInfo type with all associated metadata can be added.

ThomasNieto avatar Aug 15 '22 20:08 ThomasNieto