PowerShell / PowerShell/PSResourceGet

New/Update-PSScriptFileInfo adds required module #requires statement with -Module parameter

Open
#1,558 1 comment 0 reactions 1 assignee View on GitHub

@anamnavi is already working on this.

Since Feb 12, 2024.

Area-InfoFile Issue-Bug
Dominant language
C#
Stars
576
Forks
114
Avg merge
1d 2h
Merged PRs (30d)
7

Description

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

When creating or modifying script metadata with New-PSScriptFileInfo or Update-PSScriptFileInfo, the #requires statement is added as following:

#Requires -Module ActiveDirectory

According to About Requires document, it should be:

#Requires -Modules ActiveDirectory

It seems, that PowerShell does not care, when executing script, but for example VS Code syntax coloring does not recognize the statement any more.

Expected behavior
PS > New-PSScriptFileInfo -Path .\newscript.ps1 -Description 'problem adding module dependency' -RequiredModules @{ModuleName = 'SqlServer' } -ExternalModuleDependencies sqlserver

PS > Get-Content -Path .\newscript.ps1 | select-string '#Requires'

#Requires -Modules SqlServer
Actual behavior
PS > Update-PSScriptFileInfo -Path .\newscript.ps1 -Description 'problem adding module dependency' -RequiredModules @{ModuleName = 'SqlServer' } -ExternalModuleDependencies sqlserver

PS > Get-Content -Path .\newscript.ps1 | select-string '#Requires'

#Requires -Module SqlServer
Error details

It's not an error per se, as PowerShell seems to apply the usual cmdlet parameter shortening rules here. But it differs from documentation and confuses syntax coloring in VS Code. Even GitHub syntax coloring is confused

Environment data
Versions
--------
PSResourceGet: 1.0.1
PowerShell: 7.4.1 or 5.1
Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.