iloveJesus91
iloveJesus91

Reputation: 35

Popup window command works on powershell but not when i run it as windows bash script file

I run a command on powershell and it works fine. when i make it into a windows bash script file the same exact command i get " is not recognized as an internal or external command"

I run these commands on powershell and they work fine:

$shell = (New-Object -ComObject WScript.Shell)
$shell.Popup("Test",0,"Data Backup Info")

But when i make a windows bash file with the exact same commands, I keep getting " '$shell' is not recognized as an internal or external command, operable program or batch file."

It is the exact same command, why won't it run when I set it up as a Batch File?

Upvotes: 0

Views: 151

Answers (1)

mklement0
mklement0

Reputation: 437428

i make a windows bash file

The error message you received ("not recognized as an internal or external command, operable program or batch file") implies that you are trying to create a batch file (.cmd or .bat), i.e. a file interpreted by Windows' legacy shell, cmd.exe, rather than by bash, a shell for Unix-like environments.

From a batch file, executing PowerShell commands requires calling via PowerShell's CLI (powershell.exe for Windows PowerShell, pwsh for PowerShell (Core) 7+).

E.g., with powershell.exe, from a .cmd or .bat file:

@echo off & setlocal

powershell -c "(New-Object -ComObject WScript.Shell).Popup('Test', 0, 'Data Backup Info')"

Upvotes: 1

Related Questions