The cmdlet creates a new script file containing the required metadata needed to publish a script
package.
例
Example 1: Creating an empty script with minimal information
This example runs the cmdlet using only required parameters. The Path parameter specifies the
nane and location of the script. The Description parameter provide the description used in the
comment-based help for the script.
New-PSScriptFileInfo -Path ./test_script.ps1 -Description 'This is a test script.'
Get-Content ./test_script.ps1
<#PSScriptInfo
.VERSION 1.0.0.0
.GUID 6ec3934e-a2e0-495b-9a9c-480e555ad1d1
.AUTHOR johndoe
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
<#
.DESCRIPTION
This is a test script.
#>
Example 2: Creating a script with required modules
This example runs the cmdlet with additional parameters, including RequiredModules.
RequiredModules is an array of module specifications.
$parameters = @{
Path = './test_script2.ps1'
Description = 'This is a test script.'
Version = '2.0.0.0'
Author = 'janedoe'
RequiredModules = @(
@{ModuleName = 'PackageManagement'; ModuleVersion = '1.0.0.0' },
@{ModuleName = 'PSReadLine'}
)
}
New-PSScriptFileInfo @parameters
Get-Content ./test_script2.ps1
<#PSScriptInfo
.VERSION 2.0.0.0
.GUID 7ec4832e-a4e1-562b-8a8c-241e535ad7d7
.AUTHOR janedoe
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
#Requires -Module PSReadLine
#Requires -Module @{ ModuleName = 'PackageManagement'; ModuleVersion = '1.0.0.0' }
<#
.DESCRIPTION
This is a test script.
#>
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
The New-PSScriptFileInfo and Update-PSScriptFileInfo cmdlets place the #requires statements
for required modules between the <#PSScriptInfo and comment-based help blocks of the help file.
The Get-PSScriptFileInfo expects #requires statements to be placed somewhere before the
comment-based help block. Any #requires statements placed after the comment-based help block are
ignored by Get-PSScriptFileInfo and Publish-PSResource.