Test-ScriptFileInfo
Validerar ett kommentarsblock för ett skript.
Syntax
PathParameterSet (Standard)
Test-ScriptFileInfo
[-Path] <String>
[<CommonParameters>]
LiteralPathParameterSet
Test-ScriptFileInfo
-LiteralPath <String>
[<CommonParameters>]
Description
Cmdleten Test-ScriptFileInfo verifierar kommentarsblocket i början av ett skript som publiceras med Publish-Script cmdlet. Om kommentarsblocket har ett fel returnerar den här cmdleten information om var felet finns eller hur du korrigerar det.
Det här är en proxy-cmdlet för cmdleten Test-PSScriptFileInfo i Microsoft.PowerShell.PSResourceGet. Mer information finns i Test-PSScriptFileInfo.
Exempel
Exempel 1: Testa en skriptfil
Test-ScriptFileInfo -Path "C:\temp\temp_scripts\New-ScriptFile.ps1"
Det här kommandot testar skriptfilen New-ScriptFile.ps1 och visar resultatet. Skriptfilen innehåller giltiga metadata.
Exempel 2: Testa en skriptfil som har värden för alla metadataegenskaper
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
Det här kommandot testar skriptfilen Test-Runbook.ps1 och använder pipelineoperatorn för att skicka resultatet till cmdleten Format-List för att formatera resultatet.
Exempel 3: Testa en skriptfil som inte har några metadata
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
Det här kommandot testar skriptfilen Hello-World.ps1, som inte har några associerade metadata.
Parametrar
-LiteralPath
Anger en sökväg till en eller flera platser. Till skillnad från parametern Path används värdet för parametern LiteralPath precis som det anges. Inga tecken tolkas som wildcards. Om sökvägen innehåller escape-tecken omger du dem inom enkla citattecken. Enkla citattecken gör att PowerShell inte tolkar några tecken som escape-sekvenser.
Parametern mappas till parametern Path i Test-PSScriptFileInfo.
Parameteregenskaper
| Typ: | String |
| Standardvärde: | None |
| Stöder jokertecken: | False |
| DontShow: | False |
| Alias: | PSPath |
Parameteruppsättningar
LiteralPathParameterSet
| Position: | Named |
| Obligatorisk: | True |
| Värde från pipeline: | False |
| Värde från pipeline efter egenskapsnamn: | True |
| Värde från återstående argument: | False |
-Path
Anger en sökväg till en eller flera platser. Jokertecken tillåts. Standardplatsen är den aktuella katalogen (.).
Parameteregenskaper
| Typ: | String |
| Standardvärde: | None |
| Stöder jokertecken: | True |
| DontShow: | False |
Parameteruppsättningar
PathParameterSet
| Position: | 0 |
| Obligatorisk: | True |
| Värde från pipeline: | False |
| Värde från pipeline efter egenskapsnamn: | True |
| Värde från återstående argument: | False |
CommonParameters
Den här cmdleten stöder vanliga parametrar: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction och -WarningVariable. Mer information finns i about_CommonParameters.