Skip to content

[New Feature]: YamlCreate.ps1 should work with PowerShell StrictMode #261810

Open
@jazzdelightsme

Description

@jazzdelightsme

Description of the new feature/enhancement

PowerShell "Strict Mode" is a way to have PowerShell help you write better scripts, by complaining when your scripts violate best-practice coding rules. It helps you find bugs you may not even realize you had. See: Set-StrictMode. According to Strict Mode, YamlCreate.ps1 could use some improvement.

In addition to just making YamlCreate.ps1 better, this means it won't fail for zealots like me, who set Set-StrictMode -Version Latest in their $profile script. :D

Repro steps:

  1. Set-StrictMode -Version Latest
  2. .\Tools\YamlCreate.ps1

Expected Result:

It all just works, and looks good doing it.

Actual result:

TONS of red error spew:

PS C:\src\winget-pkgs> .\Tools\YamlCreate.ps1
Install-PackageProvider: C:\src\winget-pkgs\Tools\YamlCreate.ps1:165
Line |
 165 |      Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Fo …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Administrator rights are required to install packages in 'C:\Program Files\PackageManagement\ProviderAssemblies'. Log on to the computer with an
     | account that has Administrator rights, and then try again, or install in 'C:\Users\danthom\AppData\Local\PackageManagement\ProviderAssemblies' by
     | adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:207
Line |
 207 |  $_wingetVersion = 1.0.0
     |  ~~~~~~~~~~~~~~~~~~~~~~~
     | The property '0' cannot be found on this object. Verify that the property exists.
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:212
Line |
 212 |  if ($ScriptSettings.EnableDeveloperOptions -eq $true -and $null -ne $ …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'EnableDeveloperOptions' cannot be found on this object. Verify that the property exists.
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2623
Line |
2623 |  $script:UsingAdvancedOption = ($ScriptSettings.EnableDeveloperOptions …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'EnableDeveloperOptions' cannot be found on this object. Verify that the property exists.
InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2625
Line |
2625 |  if (!$script:UsingAdvancedOption) {
     |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The variable '$script:UsingAdvancedOption' cannot be retrieved because it has not been set.
InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2680
Line |
2680 |  if (($script:Option -eq 'QuickUpdateVersion') -and ($ScriptSettings.S …
     |       ~~~~~~~~~~~~~~
     | The variable '$script:Option' cannot be retrieved because it has not been set.

InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2699
Line |
2699 |  if (($script:Option -eq 'MovePackageIdentifier')) {
     |       ~~~~~~~~~~~~~~
     | The variable '$script:Option' cannot be retrieved because it has not been set.

[Required] Enter the Package Identifier, in the following format <Publisher shortname.Application shortname>. For example: Microsoft.Excel
PackageIdentifier:

Proposed technical implementation details (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions