Skip to content

Set-ScriptFileRequirement

SYNOPSIS

Sets correct module requirements for PowerShell scripts, ignoring local functions, [Alias()] attributes, Set-Alias-based aliases, and the '.' or '&' operators in the same folder.

SYNTAX

__AllParameterSets

Set-ScriptFileRequirement [-Path] <string> [-WhatIf] [-Confirm] [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

This function can process either a single .ps1 file or an entire folder (recursively). It uses two phases:

Phase 1 (Collection): - Parse each file to gather local function names, [Alias("...")] attributes, and Set-Alias definitions.

Phase 2 (Analysis): - Parse each file again to find commands that need external modules. - Skips: * Locally defined functions * Aliases that map to local functions * Module paths that reside in the same folder * Special operators '.' and '&' - Inserts #Requires lines for any truly external modules. - Appends #FIX: comments for commands that are not resolved.

EXAMPLES

EXAMPLE 1

Set-ScriptFileRequirement -Path "C:\MyScripts" Recursively scans C:\MyScripts, updates #Requires lines in each .ps1 file.

EXAMPLE 2

Set-ScriptFileRequirement -Path "./Scripts/Deploy.ps1" -Debug Processes only the Deploy.ps1 file, displaying debug messages with internal processing details.

PARAMETERS

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Path

A path to either a single .ps1 file or a folder.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 0
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Void

{{ Fill in the Description }}

NOTES

  • Operators '.' (dot-sourcing) and '&' (call operator) are explicitly ignored, since they are not actual commands that map to modules.

{{ Fill in the related links here }}