Creating a program alias

My Windows 10 Pro has Anaconda Powershell Prompt, and its $PSVersionTable is:

Name Value


PSVersion 5.1.19041.1682
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.19041.1682
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

I have to “run as Administrator” in order to run commands in Anaconda Powershell Prompt. I’m unfamiliar with its commands though, except to activate a conda environment. After I’ve activated a conda environment (that’s customized for Microsoft Power BI Desktop), I can start the program at C:\Program Files\WindowsApps\Microsoft.MicrosoftPowerBIDesktop_2.105.664.0_x64__8wekyb3d8bbwe\bin\PBIDesktop.exe .

Since that path is so long, I want to create a program alias. I followed the instructions to add a new key in Registry Editor. But why do I get the error:

start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
start PBIDesktop

    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

P.S. if I click on the shortcut icon for Power BI after activating the conda environment, Power BI will still show a Python script error. Apparently, it still needs to be started from the conda environment.

Hi, welcome to the forum :wave:

I know nothing about the prompt you’re using, but if it uses a PowerShell profile, get the path with:

$Profile

You can add the alias in there.

New-Alias -Name np -Value 'C:\Windows\System32\notepad.exe'

$Profile outputs: C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

But I don’t see any files in that subfolder.

Directory: C:\Users\admin\Documents\WindowsPowerShell

Mode LastWriteTime Length Name


d----- 3/25/2022 8:43 AM Scripts

Am I supposed to open Microsoft.PowerShell_profile.ps1 in a text editor to add the New-Alias? Thanks.

P.S. I assume that Ananconda Powershell Prompt loads Windows Powershell.

Yes, or do it from the prompt, whatever you prefer:

Add-Content -Path $profile -Value 'Set-Alias np C:\Windows\System32\notepad.exe'

You will need to close and reopen your console for it to take effect.

As explained in my reply, I couldn’t find Microsoft.PowerShell_profile.ps1 to be able to edit it. Since I’m unfamiliar with the commands in your code, I copy-and-pasted both lines of code into Windows Powershell. Neither line started Notepad, and neither returned an output. For the long path given in my reply, the alias that I want to create is: PBIDesktop. Should the line(s) be modified? Thanks!

You either create the file in Notepad, or use the command I provided.

The command:

Add-Content -Path $profile -Value 'Set-Alias np C:\Windows\System32\notepad.exe'

Will create the file if it doesn’t exist, and append the line to it if it does.

It doesn’t open Notepad, it’s an example of how to create an alias ‘np’ to open Notepad from the prompt.

You will need to modify it to create your own alias.

1 Like

Powershell re-opens with the error:

Set-Alias : A positional parameter cannot be found that accepts argument 'Files
\WindowsApps\Microsoft.MicrosoftPowerBIDesktop_2.105.664.0_x64__8wekyb3d8bbwe\b
in\PBIDesktop.exe'.
At
C:\Users\admin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:1
char:1
Set-Alias PBIDesktop C:\Program Files\WindowsApps\Microsoft.Microsoft ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException
FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand

Try putting the path in quotes. You have a space in the path.

Ok, my alias has linked to the program. But when I type in the alias at the Powershell prompt, the program tries to open itself as a document. The program shows an error before immediately closing:

Unable to open document
‘C:\Program Files\WindowsApps\Microsoft.MicrosoftPowerBIDesktop_2.105.664.0_x64__8wekyb3d8bbwe\bin\PBIDesktop.exe’ does not have a valid extension.

Please post the content of your profile file.

Microsoft.PowerShell_profile.ps1 has the content:
Set-Alias PowerBI 'C:\Program Files\WindowsApps\Microsoft.MicrosoftPowerBIDesktop_2.105.664.0_x64__8wekyb3d8bbwe\bin\PBIDesktop.exe'

Looks OK. I don’t have that application so I can’t test it.

Suggest setting an alias to a different app to confirm that works, and if it does, perhaps seeking further advice in a PowerBI specific forum.