Home > Software design >  Powershell profile script with input parameters
Powershell profile script with input parameters

Time:08-12

My powershell script is accessible from all folders as I inserted its path in the profile (the CurrentUserAllHosts in my case). Now I want to add input parameters to it. I tried the following:

param(
 [Parameter()]
 [string]$Parameter1
     )
write-host "$Parameter1"

calling the script (let's name it 'script.ps1') directly in its folder works as expected:

PS C:\> .\script.ps1 bla
bla
PS C:\>

calling it via the Windows profile doesn't:

PS C:\other_path\> script bla

PS C:\other_path\>

How can I get my input parameters to work via the profile like they do when calling the script directly? Is that even possible?

CodePudding user response:

If you want to invoke a script file by name alone, create an alias in the profile script:

Set-Alias -Name script -Value C:\path\to\script.ps1
  • Related