Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

New-ScriptFileInfo

Creates a script file with metadata.

Syntax

All

New-ScriptFileInfo
 [[-Path] <String>]
 -Description <String>
 [-Version <String>]
 [-Author <String>]
 [-Guid <Guid>]
 [-CompanyName <String>]
 [-Copyright <String>]
 [-RequiredModules <Object[]>]
 [-ExternalModuleDependencies <String[]>]
 [-RequiredScripts <String[]>]
 [-ExternalScriptDependencies <String[]>]
 [-Tags <String[]>]
 [-ProjectUri <Uri>]
 [-LicenseUri <Uri>]
 [-IconUri <Uri>]
 [-ReleaseNotes <String[]>]
 [-PrivateData <String>]
 [-PassThru]
 [-Force]
 [-WhatIf]
 [-Confirm]
 [<CommonParameters>]

Description

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.

Examples

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.

Test-ScriptFileInfo -Path C:\Test\Temp-Scriptfile.ps1
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.

$Parms = @{
 Path = "C:\Test\New-ScriptFile.ps1"
 Verbose = $True
 Version = "1.0"
 Author = "pattif@contoso.com"
 Description = "My new script file test"
 CompanyName = "Contoso Corporation"
 Copyright = "2019 Contoso Corporation. All rights reserved."
 ExternalModuleDependencies = "ff","bb"
 RequiredScripts = "Start-WFContosoServer", "Stop-ContosoServerScript"
 ExternalScriptDependencies = "Stop-ContosoServerScript"
 Tags = @("Tag1", "Tag2", "Tag3")
 ProjectUri = "https://contoso.com"
 LicenseUri = "https://contoso.com/License"
 IconUri = "https://contoso.com/Icon"
 PassThru = $True
 ReleaseNotes = @("Contoso script now supports the following features:",
 "Feature 1",
 "Feature 2",
 "Feature 3",
 "Feature 4",
 "Feature 5")
 RequiredModules =
 "1",
 "2",
 "RequiredModule1",
 @{ModuleName="RequiredModule2";ModuleVersion="1.0"},
 @{ModuleName="RequiredModule3";RequiredVersion="2.0"},
 "ExternalModule1"
 }
New-ScriptFileInfo @Parms
VERBOSE: Performing the operation "Creating the 'C:\Test\New-ScriptFile.ps1'
 PowerShell Script file" on target "C:\Test\New-ScriptFile.ps1".

<#PSScriptInfo

.VERSION 1.0

.GUID 4fabe8c7-7862-45b1-a72e-1352a433b77d

.AUTHOR pattif@contoso.com

.COMPANYNAME Contoso Corporation

.COPYRIGHT 2019 Contoso Corporation. All rights reserved.

.TAGS Tag1 Tag2 Tag3

.LICENSEURI https://contoso.com/License

.PROJECTURI https://contoso.com/

.ICONURI https://contoso.com/Icon

.EXTERNALMODULEDEPENDENCIES ff,bb

.REQUIREDSCRIPTS Start-WFContosoServer,Stop-ContosoServerScript

.EXTERNALSCRIPTDEPENDENCIES Stop-ContosoServerScript

.RELEASENOTES
Contoso script now supports the following features:
Feature 1
Feature 2
Feature 3
Feature 4
Feature 5

.PRIVATEDATA

#>

#Requires -Module 1
#Requires -Module 2
#Requires -Module RequiredModule1
#Requires -Module @{ModuleName = 'RequiredModule2'; ModuleVersion = '1.0'}
#Requires -Module @{RequiredVersion = '2.0'; ModuleName = 'RequiredModule3'}
#Requires -Module ExternalModule1

<#

.DESCRIPTION
 My new script file test

#>
Param()

Parameters

-Author

Specifies the script author.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-CompanyName

Specifies the company or vendor who created the script.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Confirm

Prompts you for confirmation before running the New-ScriptFileInfo.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

-Copyright

Specifies a copyright statement for the script.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Description

Specifies a description for the script.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ExternalModuleDependencies

Specifies an array of external module dependencies.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ExternalScriptDependencies

Specifies an array of external script dependencies.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Force

Forces the command to run without asking for user confirmation.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Guid

Specifies a unique ID for the script.

Parameter properties

Type:Guid
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-IconUri

Specifies the URL of an icon for the script. The specified icon is displayed on the gallery web page for the script.

Parameter properties

Type:Uri
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-LicenseUri

Specifies the URL of licensing terms.

Parameter properties

Type:Uri
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-PassThru

Returns an object that represents the item with which you're working. By default, New-ScriptFileInfo doesn't generate any output.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Path

Specifies the location where the script file is saved.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-PrivateData

Specifies private data for the script.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ProjectUri

Specifies the URL of a web page about this project.

Parameter properties

Type:Uri
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ReleaseNotes

Specifies a string array that contains release notes or comments that you want available to users of this version of the script.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-RequiredModules

Specifies modules that must be in the global session state. If the required modules aren't in the global session state, PowerShell imports them.

Parameter properties

Type:

Object[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-RequiredScripts

Specifies an array of required scripts.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Tags

Specifies an array of tags.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Version

Specifies the version of the script.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-WhatIf

Shows what would happen if New-ScriptFileInfo runs. The cmdlet isn't run.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

CommonParameters

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.

Inputs

String

Outputs

Object

Related Links


Feedback

Was this page helpful?