The New-ScriptFileInfo cmdlet creates a PowerShell script file, including metadata about the
script.
The examples use splatting to pass parameters to the New-ScriptFileInfo cmdlet. For more
information, see about_Splatting.
示例
Example 1: Create a script file and specify its version, author, and description
In this example, a script file is created and its contents are displayed in the PowerShell console.
$Parms = @{
Path = "C:\Test\Temp-Scriptfile.ps1"
Version = "1.0"
Author = "pattif@contoso.com"
Description = "My test script file description goes here"
}
New-ScriptFileInfo @Parms
Get-Content -Path C:\Test\Temp-Scriptfile.ps1
<#PSScriptInfo
.VERSION 1.0
.GUID 3bb10ee7-38c1-41b9-88ea-16899164fc19
.AUTHOR pattif@contoso.com
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
<#
.DESCRIPTION
My test script file description goes here
#>
Param()
The New-ScriptFileInfo cmdlet uses splatting to configure several parameters for the script.
Path sets the ___location and name of the script. Version specifies the script's version
number. Author is the email address of the person who created the script. Description
explains the script's purpose.
After the script is created, Get-Content uses the Path parameter to locate the script. The
script's contents are displayed in the PowerShell console.
Example 2: Test a script file
In this example, the metadata for the script created in Example 1 is tested.
Version Name Author Description
------- ---- ------ -----------
1.0 Temp-Scriptfile pattif@contoso.com My test script file description goes here
The Test-ScriptFileInfo cmdlet uses the Path parameter to specify the script file's ___location.
Example 3: Create a script file with all the metadata properties
This example uses splatting to create a script file named New-ScriptFile.ps1 that includes all its
metadata properties. The Verbose parameter specifies that verbose output is displayed as the
script is created.
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.