Skip to content

Bug with Save-PSResource #1837

@alerickson

Description

@alerickson

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

The following commented out test in 'FindPSResourceLocal.Tests.ps1' is failing with Find-PSResource throwing an unexpected error:

    It "find resource given Name, Version null (package containing nuspec only)" {
        # FindName()
        $pkgName = "PowerShell"
        Save-PSResource -Name $pkgName -Repository "NuGetGallery" -Path $localRepoUriAddress -AsNupkg -TrustRepository
        $res = Find-PSResource -Name $pkgName -Repository $localRepo
        $res.Name | Should -Be $pkgName
        $res.Repository | Should -Be $localRepo
    }

Use any local path as the local repository.

Expected behavior

Find-PSResource should save and produce no errors.

Actual behavior

Find-PSResource: The command 'ConvertFrom-StringData' is not allowed in restricted language mode or a Data section.

Error details

Exception             :
    Type        : System.Management.Automation.ParseException
    Errors      :
        Extent  : ConvertFrom-StringData -StringData @'
                  ###PSLOC
                  InValidUri         = InValid Uri: '{0}'. A sample valid uri:
https://www.powershellgallery.com/api/v2/.
                  PathDoesNotExist   = Path: '{0}' does not exist.
                  VersionError       = MinimumVersion should be less than the MaximumVersion. The MinimumVersion or
MaximumVersion cannot be used with the RequiredVersion in the same command.
                  UnexpectedArgument = Unexpected argument type: '{0}'.
                  SourceNotFound     = Source '{0}' not found. Please make sure you register it.
                  CallingFunction    = Calling function '{0}'.
                  PropertyTypeInvalidForDesiredValues = Property 'DesiredValues' must be either a
[System.Collections.Hashtable], [CimInstance] or [PSBoundParametersDictionary]. The type detected was {0}.
                  PropertyTypeInvalidForValuesToCheck = If 'DesiredValues' is a CimInstance, then property
'ValuesToCheck' must contain a value.
                  PropertyValidationError = Expected to find an array value for property {0} in the current values,
but it was either not present or was null. This has caused the test method to return false.
                  PropertiesDoesNotMatch = Found an array for property {0} in the current values, but this array does
not match the desired state. Details of the changes are below.
                  PropertyThatDoesNotMatch = {0} - {1}
                  ValueOfTypeDoesNotMatch = {0} value for property {1} does not match. Current state is '{2}' and
desired state is '{3}'.
                  UnableToCompareProperty = Unable to compare property {0} as the type {1} is not handled by the
Test-SQLDSCParameterState cmdlet.
                  ###PSLOC
                  '@
        ErrorId : CmdletNotInAllowedListForDataSection
        Message : The command 'ConvertFrom-StringData' is not allowed in restricted language mode or a Data section.
    Message     : At line:13 char:1
                  + ConvertFrom-StringData -StringData @'
                  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  The command 'ConvertFrom-StringData' is not allowed in restricted language mode or a Data section.
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : At line:13 char:1
                      + ConvertFrom-StringData -StringData @'
                      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      The command 'ConvertFrom-StringData' is not allowed in restricted language mode or a Data
section.
            HResult : -2146233087
        CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : CmdletNotInAllowedListForDataSection
        InvocationInfo        :
            ScriptLineNumber : 13
            OffsetInLine     : 1
            HistoryId        : -1
            Line             : ConvertFrom-StringData -StringData @'

            Statement        : ConvertFrom-StringData -StringData @'
                               ###PSLOC
                               InValidUri         = InValid Uri: '{0}'. A sample valid uri:
https://www.powershellgallery.com/api/v2/.
                               PathDoesNotExist   = Path: '{0}' does not exist.
                               VersionError       = MinimumVersion should be less than the MaximumVersion. The
MinimumVersion or MaximumVersion cannot be used with the RequiredVersion in the same command.
                               UnexpectedArgument = Unexpected argument type: '{0}'.
                               SourceNotFound     = Source '{0}' not found. Please make sure you register it.
                               CallingFunction    = Calling function '{0}'.
                               PropertyTypeInvalidForDesiredValues = Property 'DesiredValues' must be either a
[System.Collections.Hashtable], [CimInstance] or [PSBoundParametersDictionary]. The type detected was {0}.
                               PropertyTypeInvalidForValuesToCheck = If 'DesiredValues' is a CimInstance, then
property 'ValuesToCheck' must contain a value.
                               PropertyValidationError = Expected to find an array value for property {0} in the
current values, but it was either not present or was null. This has caused the test method to return false.
                               PropertiesDoesNotMatch = Found an array for property {0} in the current values, but
this array does not match the desired state. Details of the changes are below.
                               PropertyThatDoesNotMatch = {0} - {1}
                               ValueOfTypeDoesNotMatch = {0} value for property {1} does not match. Current state is
'{2}' and desired state is '{3}'.
                               UnableToCompareProperty = Unable to compare property {0} as the type {1} is not handled
by the Test-SQLDSCParameterState cmdlet.
                               ###PSLOC
                               '@
            PositionMessage  : At line:13 char:1
                               + ConvertFrom-StringData -StringData @'
                               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite  :
        Name          : CheckRestrictedLanguage
        DeclaringType : [System.Management.Automation.ScriptBlock]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.ScriptBlock.CheckRestrictedLanguage(IEnumerable`1 allowedCommands, IEnumerable`1
allowedVariables, Boolean allowEnvironmentVariables)
   at Microsoft.PowerShell.PSResourceGet.UtilClasses.Utils.TryReadPSDataFile(String filePath, String[]
allowedVariables, String[] allowedCommands, Boolean allowEnvironmentVariables, Hashtable& dataFileInfo, Exception&
error) in C:\code\PSResourceGet\src\code\Utils.cs:line 1286
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.LocalServerAPICalls
CategoryInfo          : ParserError: (Microsoft.PowerShel…LocalServerAPICalls:LocalServerAPICalls) [Find-PSResource],
ParseException
FullyQualifiedErrorId : GetMetadataFromNupkgFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
InvocationInfo        :
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 19
    Line             : find-psresource "PowerShell" -Repository code
    Statement        : find-psresource "PowerShell" -Repository code
    PositionMessage  : At line:1 char:1
                       + find-psresource "PowerShell" -Repository code
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : find-psresource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.1.0                 Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-Instal…


Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions