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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.