Test-ScriptFileInfo
Convalida un blocco di commenti per uno script.
Sintassi
PathParameterSet (Impostazione predefinita)
Test-ScriptFileInfo
[-Path] <String>
[<CommonParameters>]
LiteralPathParameterSet
Test-ScriptFileInfo
-LiteralPath <String>
[<CommonParameters>]
Descrizione
Il Test-ScriptFileInfo cmdlet convalida il blocco di commenti all'inizio di uno script che verrà pubblicato con il cmdlet Publish-Script. Se il blocco di commenti presenta un errore, questo cmdlet restituisce informazioni sulla posizione dell'errore o su come correggerlo.
Esempio
Esempio 1: Testare un file di script
Test-ScriptFileInfo -Path "C:\temp\temp_scripts\New-ScriptFile.ps1"
Questo comando testa il file di script New-ScriptFile.ps1 e visualizza i risultati. Il file di script include metadati validi.
Esempio 2: Testare un file di script con valori per tutte le proprietà dei metadati
Test-ScriptFileInfo -Path "D:\code\Test-Runbook.ps1" | Format-List *
Name : Test-Runbook
Path : D:\code\Test-Runbook.ps1
ScriptBase : D:\code
ReleaseNotes : {contoso script now supports following features, Feature 1, Feature 2, Feature 3...}
Version : 1.0
Guid : eb246b19-17da-4392-8c89-7c280f69ad0e
Author : pattif
CompanyName : Microsoft Corporation
Copyright : 2015 Microsoft Corporation. All rights reserved.
Tags : {Tag1, Tag2, Tag3}
LicenseUri : https://contoso.com/License
ProjectUri : https://contoso.com/
IconUri : https://contoso.com/MyScriptIcon
ExternalModuleDependencies : ExternalModule1
RequiredScripts : {Start-WFContosoServer, Stop-ContosoServerScript}
ExternalScriptDependencies : Stop-ContosoServerScript
Description : Contoso Script example
RequiredModules : {RequiredModule1, @{ ModuleName = 'RequiredModule2'; ModuleVersion = '1.0' }, @{ ModuleName = 'RequiredModule3'; RequiredVersion = '2.0' }, ExternalModule1}
ExportedCommands : {Test-WebUri, ValidateAndAdd-PSScriptInfoEntry, Get-PSScriptInfo, My-Workflow...}
ExportedFunctions : {Test-WebUri, ValidateAndAdd-PSScriptInfoEntry, Get-PSScriptInfo, My-AdvPSCmdlet}
ExportedWorkflows : My-Workflow
Questo comando testa il file di script Test-Runbook.ps1 e usa l'operatore pipeline per passare i risultati al cmdlet Format-List per formattare i risultati.
Esempio 3: Testare un file di script senza metadati
Test-ScriptFileInfo -Path "D:\code\Hello-World.ps1"
Test-ScriptFileInfo : Script 'D:\code\Hello-World.ps1' is missing required metadata properties. Verify that the script file has Version, Description
and Author properties. You can use the Update-ScriptFileInfo or New-ScriptFileInfo cmdlet to add or update the PSScriptInfo to the script file.
At line:1 char:1
+ Test-ScriptFileInfo D:\code\Hello-World.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (D:\code\Hello-World.ps1:String) [Test-ScriptFileInfo], ArgumentException
+ FullyQualifiedErrorId : MissingRequiredPSScriptInfoProperties,Test-ScriptFile
Questo comando testa il file di script Hello-World.ps1, che non dispone di metadati associati.
Parametri
-LiteralPath
Specifica un percorso per una o più posizioni. A differenza del parametro Path , il valore del parametro LiteralPath viene usato esattamente come viene immesso. Nessun carattere viene interpretato come metacaratteri. Se il percorso include caratteri di escape, racchiuderli tra virgolette singole. Le virgolette singole indicano a PowerShell di non interpretare alcun carattere come sequenze di escape.
Proprietà dei parametri
| Tipo: | String |
| Valore predefinito: | None |
| Supporta i caratteri jolly: | False |
| DontShow: | False |
| Alias: | PSPath |
Set di parametri
LiteralPathParameterSet
| Posizione: | Named |
| Obbligatorio: | True |
| Valore dalla pipeline: | False |
| Valore dalla pipeline in base al nome della proprietà: | True |
| Valore dagli argomenti rimanenti: | False |
-Path
Specifica un percorso per una o più posizioni. Sono consentiti i metacaratteri. Il percorso predefinito è la directory corrente (.).
Proprietà dei parametri
| Tipo: | String |
| Valore predefinito: | None |
| Supporta i caratteri jolly: | True |
| DontShow: | False |
Set di parametri
PathParameterSet
| Posizione: | 0 |
| Obbligatorio: | True |
| Valore dalla pipeline: | False |
| Valore dalla pipeline in base al nome della proprietà: | True |
| Valore dagli argomenti rimanenti: | False |
CommonParameters
Questo cmdlet supporta i parametri comuni: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction e -WarningVariable. Per altre informazioni, vedi about_CommonParameters.