如何使用 New-ScriptFileInfo PrivateData?
How do I make use of New-ScriptFileInfo PrivateData?
我一直在使用与脚本文件同名的 PSD1 文件(例如 Foo.ps1 --> Foo.psd1)来存储我的脚本设置。我在想我也许可以利用脚本的 PrivateData
部分来存储此信息,这些信息将在脚本发布时包含在 InstallScriptInfos
文件夹中。
New-ScriptFileInfo 命令有一个名为 PrivateData
的 string
参数,我希望创建一个类似于 PSD1
文件中存在的部分(为简洁起见缩写) ):
PrivateData = @{
PSData = @{
# Prerelease = ''
# Tags = @()
# LicenseUri = ''
# ProjectUri = ''
# IconUri = ''
# ReleaseNotes = ''
}
}
但是,当创建一个新的脚本文件时,设置这个参数:
PS> New-ScriptInfo -Path .\Foo.ps1 -Description 'lorem ipsum' -PrivateData @{Key='Value'}
结果为字符串:
<#PSScriptInfo
.VERSION 1.0
.GUID 4652dc63-6433-494a-8dcb-55cec29191d4
.AUTHOR pattif@contoso.com
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA System.Collections.Hashtable
#>
<#
.DESCRIPTION
lorem ipsum
#>
Param()
如果此脚本发布到存储库:
Publish-Script -Path .\Foo.ps1 -Repository 'MyRepository'
结果 InstallScriptInfos\foo_InstalledScriptInfo
不包含这条元数据:
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>Microsoft.PowerShell.Commands.PSRepositoryItemInfo</T>
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
<MS>
<S N="Name">foo</S>
<S N="Version">1.0</S>
<S N="Type">Script</S>
<S N="Description">lorem ipsum</S>
<S N="Author">pattif@contoso.com</S>
<Obj N="CompanyName" RefId="1">
<TN RefId="1">
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
</Obj>
<Nil N="Copyright" />
<Ref N="PublishedDate" RefId="1" />
<Obj N="InstalledDate" RefId="2">
<DT>2020-10-08T09:28:45.542507-05:00</DT>
<MS>
<Obj N="DisplayHint" RefId="3">
<TN RefId="2">
<T>Microsoft.PowerShell.Commands.DisplayHintType</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>DateTime</ToString>
<I32>2</I32>
</Obj>
</MS>
</Obj>
<Nil N="UpdatedDate" />
<Nil N="LicenseUri" />
<Nil N="ProjectUri" />
<Nil N="IconUri" />
<Obj N="Tags" RefId="4">
<TN RefId="3">
<T>System.Object[]</T>
<T>System.Array</T>
<T>System.Object</T>
</TN>
<LST>
<S>PSScript</S>
</LST>
</Obj>
<Obj N="Includes" RefId="5">
<TN RefId="4">
<T>System.Collections.Hashtable</T>
<T>System.Object</T>
</TN>
<DCT>
<En>
<S N="Key">DscResource</S>
<Obj N="Value" RefId="6">
<TNRef RefId="3" />
<LST />
</Obj>
</En>
<En>
<S N="Key">Function</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">RoleCapability</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Workflow</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Command</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Cmdlet</S>
<Ref N="Value" RefId="6" />
</En>
</DCT>
</Obj>
<Nil N="PowerShellGetFormatVersion" />
<Nil N="ReleaseNotes" />
<Obj N="Dependencies" RefId="7">
<TNRef RefId="3" />
<LST />
</Obj>
<S N="RepositorySourceLocation">/Volumes/PowerShellRepository</S>
<S N="Repository">MyRepository</S>
<S N="PackageManagementProvider">NuGet</S>
<Obj N="AdditionalMetadata" RefId="8">
<TNRef RefId="1" />
<MS>
<S N="description">lorem ipsum</S>
<S N="requireLicenseAcceptance">False</S>
<S N="isLatestVersion">False</S>
<S N="isAbsoluteLatestVersion">False</S>
<S N="tags">PSScript</S>
<S N="developmentDependency">False</S>
<B N="IsPrerelease">false</B>
</MS>
</Obj>
<S N="InstalledLocation">/Users/craig/.local/share/powershell/Scripts</S>
</MS>
</Obj>
</Objs>
这个参数的用途是什么?
该参数的目的是存储有关画廊使用的实际模块的信息元数据。 ctrl + F privatedata
例如,如果您要向您的私有数据添加一些标签,其中一个是“banana”,那么另一个用户可以这样做来找到您的模块
Find-Script -Tag "banana"
这比预期的要容易:
<#PSScriptInfo
.VERSION 0.0.0
.GUID 8249e67f-497d-4cef-aed1-4b2ccf56f974
.AUTHOR First Last
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA @{ Foo=123; Bar=$true; Name='lorem' }
#>
<#
.DESCRIPTION
lorem ipsum
#>
$Info = Test-ScriptFileInfo $PSCommandPath
Invoke-Expression $Info.PrivateData
Name Value
---- -----
Foo 123
Bar True
Name lorem
我一直在使用与脚本文件同名的 PSD1 文件(例如 Foo.ps1 --> Foo.psd1)来存储我的脚本设置。我在想我也许可以利用脚本的 PrivateData
部分来存储此信息,这些信息将在脚本发布时包含在 InstallScriptInfos
文件夹中。
New-ScriptFileInfo 命令有一个名为 PrivateData
的 string
参数,我希望创建一个类似于 PSD1
文件中存在的部分(为简洁起见缩写) ):
PrivateData = @{
PSData = @{
# Prerelease = ''
# Tags = @()
# LicenseUri = ''
# ProjectUri = ''
# IconUri = ''
# ReleaseNotes = ''
}
}
但是,当创建一个新的脚本文件时,设置这个参数:
PS> New-ScriptInfo -Path .\Foo.ps1 -Description 'lorem ipsum' -PrivateData @{Key='Value'}
结果为字符串:
<#PSScriptInfo
.VERSION 1.0
.GUID 4652dc63-6433-494a-8dcb-55cec29191d4
.AUTHOR pattif@contoso.com
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA System.Collections.Hashtable
#>
<#
.DESCRIPTION
lorem ipsum
#>
Param()
如果此脚本发布到存储库:
Publish-Script -Path .\Foo.ps1 -Repository 'MyRepository'
结果 InstallScriptInfos\foo_InstalledScriptInfo
不包含这条元数据:
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>Microsoft.PowerShell.Commands.PSRepositoryItemInfo</T>
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
<MS>
<S N="Name">foo</S>
<S N="Version">1.0</S>
<S N="Type">Script</S>
<S N="Description">lorem ipsum</S>
<S N="Author">pattif@contoso.com</S>
<Obj N="CompanyName" RefId="1">
<TN RefId="1">
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
</Obj>
<Nil N="Copyright" />
<Ref N="PublishedDate" RefId="1" />
<Obj N="InstalledDate" RefId="2">
<DT>2020-10-08T09:28:45.542507-05:00</DT>
<MS>
<Obj N="DisplayHint" RefId="3">
<TN RefId="2">
<T>Microsoft.PowerShell.Commands.DisplayHintType</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>DateTime</ToString>
<I32>2</I32>
</Obj>
</MS>
</Obj>
<Nil N="UpdatedDate" />
<Nil N="LicenseUri" />
<Nil N="ProjectUri" />
<Nil N="IconUri" />
<Obj N="Tags" RefId="4">
<TN RefId="3">
<T>System.Object[]</T>
<T>System.Array</T>
<T>System.Object</T>
</TN>
<LST>
<S>PSScript</S>
</LST>
</Obj>
<Obj N="Includes" RefId="5">
<TN RefId="4">
<T>System.Collections.Hashtable</T>
<T>System.Object</T>
</TN>
<DCT>
<En>
<S N="Key">DscResource</S>
<Obj N="Value" RefId="6">
<TNRef RefId="3" />
<LST />
</Obj>
</En>
<En>
<S N="Key">Function</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">RoleCapability</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Workflow</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Command</S>
<Ref N="Value" RefId="6" />
</En>
<En>
<S N="Key">Cmdlet</S>
<Ref N="Value" RefId="6" />
</En>
</DCT>
</Obj>
<Nil N="PowerShellGetFormatVersion" />
<Nil N="ReleaseNotes" />
<Obj N="Dependencies" RefId="7">
<TNRef RefId="3" />
<LST />
</Obj>
<S N="RepositorySourceLocation">/Volumes/PowerShellRepository</S>
<S N="Repository">MyRepository</S>
<S N="PackageManagementProvider">NuGet</S>
<Obj N="AdditionalMetadata" RefId="8">
<TNRef RefId="1" />
<MS>
<S N="description">lorem ipsum</S>
<S N="requireLicenseAcceptance">False</S>
<S N="isLatestVersion">False</S>
<S N="isAbsoluteLatestVersion">False</S>
<S N="tags">PSScript</S>
<S N="developmentDependency">False</S>
<B N="IsPrerelease">false</B>
</MS>
</Obj>
<S N="InstalledLocation">/Users/craig/.local/share/powershell/Scripts</S>
</MS>
</Obj>
</Objs>
这个参数的用途是什么?
该参数的目的是存储有关画廊使用的实际模块的信息元数据。 ctrl + F privatedata
例如,如果您要向您的私有数据添加一些标签,其中一个是“banana”,那么另一个用户可以这样做来找到您的模块
Find-Script -Tag "banana"
这比预期的要容易:
<#PSScriptInfo
.VERSION 0.0.0
.GUID 8249e67f-497d-4cef-aed1-4b2ccf56f974
.AUTHOR First Last
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA @{ Foo=123; Bar=$true; Name='lorem' }
#>
<#
.DESCRIPTION
lorem ipsum
#>
$Info = Test-ScriptFileInfo $PSCommandPath
Invoke-Expression $Info.PrivateData
Name Value
---- -----
Foo 123
Bar True
Name lorem