PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
483 stars 92 forks source link

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

Open peetrike opened 7 months ago

peetrike commented 7 months ago

Prerequisites

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 ActiveDirectory

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 ActiveDirectory

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. Event GitHub syntax coloring is confused

Environment data

Versions
--------
PSResourceGet: 1.0.1
PowerShell: 7.4.1 or 5.1

Visuals

No response

peetrike commented 7 months ago

When I tried to run script, even the following statement loaded required module:

#Requires -M ActiveDirectory