1
votes

I tried the solution given from: Specify the size of command prompt when executing a batch file

I ran:

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

But I get these errors, any ideas?

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. At line:1 char:22 + &{set-executionpolicy <<<< remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize} + CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

Import-Module : The specified module 'SetConsoleFont' was not loaded because no valid module file was found in any module directory . At line:1 char:50 + &{set-executionpolicy remotesigned; Import-Module <<<< SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize} + CategoryInfo : ResourceUnavailable: (SetConsoleFont:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

The term 'Get-ConsoleFontInfo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spe lling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:86 + &{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo <<<< | Format-Table -AutoSize} + CategoryInfo : ObjectNotFound: (Get-ConsoleFontInfo:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I have put the file SetConsoleFont.psm1 in

C:\Users\Adrian\Documents\WindowsPowerShell\Modules\SetConsoleFont

You say "You're not allowed to set the execution policy" well maybe I'm not, but it's my machine so why shouldn't I? I don't want to execute these commands as Administrator, just as a user, me (Adrian)

Another comment was to try set-executionpolicy bypass process

so I tried:

powershell -command "&{set-executionpolicy bypass process; set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

But got even more red errors.

I have no idea what powershell is or how to use it, I just want to change the font from a batch file without hassle!

3
The error messages tell you everything you need to know. You're not allowed to set the execution policy (you may need to try it with an elevated powershell prompt (Run As Administrator)), and you don't have a module called SetConsoleFont (you need to find it, download it, verify that it's not doing anything nasty to your system, and install it).Jeff Zeitlin
updated the question as I can't write my response here coz it's too longArthur
Thanks James C. I already got that but got the errors as describedArthur

3 Answers

0
votes

Try set-executionpolicy bypass process instead.

Also make sure you have put the module in a module path folder such as:

[yourprofile]\Documents\WindowsPowershell\Modules

0
votes

I managed to get it working but only in a PowerShell console, and I had to run it as Administrator. However this is not practical for me for the following reasons:

I wish to change the font of new window seamlessly from a batch file, which will be run by users of the software. They may not have Administrator access and so cannot execute "set-executionpolicy remotesigned" which I needed to do to get it working.

Also this has to be done in a DOS batch file, so opening up a powershell window is not an option. It only works in a PowerShell window and not with the DOS "powershell -command" option.

So a partial answer.

0
votes

If you want to change Execution Policy, it should be done in an elevated prompt.

And loading the module can be done by giving absolute path. Example is below.

Import-Module c:\users\testuser\desktop\SetConsoleFont.psm1 -Verbose

and we can bypass execution policy like below.

powershell.exe -executionpolicy bypass -command "${<your code>}"

Edit: The imported module will be available only in the scope of the script block.

here it is with in {}. So whatever cmdlets and functions in side the module should be executed in sided the scriptblock.

Regards,

Kvprasoon