2

I know nothing of PowerShell, but I wanted to install this: https://www.powershellgallery.com/packages/lolcat/

So, I start PowerShell as administrator, and:

PS C:\WINDOWS\system32> Install-Module -Name lolcat                                                                                                                                                                                             NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Me\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import
 the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\WINDOWS\system32> lolcat

Usage: lolcat [OPTION]... [FILE1[, FILE2[, ...]]]
...

Nice, it works. So first I find where is the newly installed script:

PS C:\WINDOWS\system32> (Get-Module lolcat).Path
C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1

Ok, so now I want to try calling this from cmd.exe:

C:\Users>PowerShell.exe -File "C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1"
Processing -File 'C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

Nope, does not work.

Is it possible to call this PowerShell script from cmd.exe - and if so, how?

2 Answers 2

3

The error is due to the fact that the -File parameter from the powershell.exe excepts a .ps1 file.

If you want to run C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1 from cmd, make a .ps1 script where you can write something like

Import-Module lolcat

# now you have all the functions from the lolcat module loaded into this PowerShell session

# do stuff

And then call this script from cmd.

The difference between .ps1 and .psm1 is explained here.

Sign up to request clarification or add additional context in comments.

Comments

0

Eh, turned out to be less complicated then I thought - since it is a "module", just use the module name:

C:\Users>PowerShell.exe lolcat

Usage: lolcat [OPTION]... [FILE1[, FILE2[, ...]]]

...

1 Comment

You don't actually run a module file. When you install a module and import it into your powershell session functions are loaded which you can call from any location. If you do Get-Command -Module lolcat you will see what these functions are. One of these functions is called lolcat, however there are 2 others. Out-Rainbow is one of them. Use at the end of any pipeline for some colorful output. dir | Out-Rainbow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.