New-ScriptFileInfo
使用元数据创建脚本文件。
语法
New-ScriptFileInfo
[[-Path] <String>]
[-Version <String>]
[-Author <String>]
-Description <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>]
说明
cmdlet New-ScriptFileInfo
创建 PowerShell 脚本文件,包括有关脚本的元数据。
这是 Microsoft.PowerShell.PSResourceGet 中 cmdlet 的代理 New-PSScriptFileInfo
cmdlet。 有关详细信息,请参阅 New-PSScriptFileInfo。
示例
示例 1:创建脚本文件并指定其版本、作者和说明
在此示例中,将创建一个脚本文件,其内容显示在 PowerShell 控制台中。
$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()
cmdlet New-ScriptFileInfo
使用 splatting 为脚本配置多个参数。
路径 设置脚本的位置和名称。 Version 指定脚本的版本号。 作者 是创建脚本的人员的电子邮件地址。 说明 说明了脚本的用途。
创建脚本后, Get-Content
使用 Path 参数查找脚本。 脚本的内容显示在 PowerShell 控制台中。
示例 2:测试脚本文件
在此示例中,测试了 示例 1 中创建的脚本的元数据。
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
cmdlet Test-ScriptFileInfo
使用 Path 参数指定脚本文件的位置。
示例 3:创建包含所有元数据属性的脚本文件
此示例使用 splatting 创建名为 New-ScriptFile.ps1
的脚本文件,其中包含其所有元数据属性。 Verbose 参数指定在创建脚本时显示详细输出。
$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()
参数
-Author
指定脚本作者。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-CompanyName
指定创建脚本的公司或供应商。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Confirm
在运行 New-ScriptFileInfo
之前提示你进行确认。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Copyright
指定脚本的版权声明。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Description
指定脚本的说明。
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ExternalModuleDependencies
指定外部模块依赖项的数组。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ExternalScriptDependencies
指定外部脚本依赖项的数组。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
强制运行命令而不要求用户确认。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Guid
指定脚本的唯一 ID。
Type: | Guid |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IconUri
指定脚本图标的 URL。 指定的图标显示在脚本的库网页上。
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LicenseUri
指定许可条款的 URL。
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-PassThru
代理 cmdlet 忽略此参数,因为它不受 New-PSScriptFileInfo
支持。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Path
指定保存脚本文件的位置。
Type: | String |
Position: | 0 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-PrivateData
指定脚本的私有数据。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ProjectUri
指定有关此项目的网页的 URL。
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ReleaseNotes
指定一个字符串数组,其中包含你希望此版本的脚本用户可用的发行说明或注释。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RequiredModules
指定必须处于全局会话状态的模块。 如果所需的模块不处于全局会话状态,PowerShell 会导入它们。
Type: | Object[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RequiredScripts
指定所需脚本的数组。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Tags
指定标记的数组。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Version
指定脚本的版本。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
显示运行后 New-ScriptFileInfo
会发生什么情况。 cmdlet 未运行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |