0

I have to run some PowerShell scripts to run a app. I'm able to run all of them except this single one:

Param(
    [string]$cmd = "start"
)

$script = $myInvocation.MyCommand.Name
$host.UI.RawUI.WindowTitle = $script

function StartServer {
    kafka-server-start $env:KAFKA_DIR\config\server.properties
}

function StopServer {
    kafka-server-stop
}

switch ($cmd) {
    "start" { StartServer; break }
    "stop" { StopServer; break }
    "shutdown" { StopServer; break }
    default { Write-Host "$script [cmd=start|stop|shutdown]" }
}

If I try to run this script, I get a message that the command "wmic" could not be found. I'm not using a command "wmin". I'm just trying to start the script by typing ./nameOfScript.

Justin
  • 153
  • 1
  • 1
  • 8
  • Please show the complete, unaltered error message. Most likely the error isn't caused directly by your script, but by something that your script invokes. – Ansgar Wiechers Jan 13 '18 at 22:56
  • It's on germany. If I translate it: "The command "wmic" is either misspelled or could not be found". Thats it! I'm not even using this command? – Justin Jan 13 '18 at 23:02
  • 1
    A quick search on google for your error finds this: [Not able to start kafka with .\bin\windows\kafka-server-start.bat .\config\server.properties cmd](https://stackoverflow.com/q/42555596/847990) –  Jan 14 '18 at 01:30

1 Answers1

0

This error is because you don't have WMIC in your System Path or it's been deleted from your system by someone else or by your enterprise build standard/SOP.

WMIC has been part of Windows for many years and till in Windows 10 and Windows Server 2016.

It was the other script tool many did not even know was there and thus never used it as it was intended. As a former avid WMIC user, WMIC was the predecessor to PowerShell IMHO. If you look at the WMIC docs or the stuff all over the web about it, you'll see that I mean.


WMIC - Take Command-line Control over WMI Microsoft is creating a lot of good reasons to make the command prompt in Windows XP and the Windows Server 2003 family your home for systems management. Windows Management Instrumentation Command-line (WMIC), which uses the power of Windows Management Instrumentation (WMI) to enable systems management from the command line, is one of those reasons.

WMI has been an important part of Microsoft's systems management initiative since Microsoft Systems Management Server (SMS) 2.0 and has grown in popularity since the introduction of Windows 2000. However, until the introduction of WMIC, you couldn't easily access the WMI repository or the WMI namespace from a command prompt.

https://msdn.microsoft.com/en-us/library/bb742610.aspx

wmic vs WMI Powershell cmdlets The WMI command-line (WMIC) utility provides a command-line interface for WMI. With Windows 7 you can do everything that you can do with wmic using Windows Powershell and much more by leveraging powerful features of Windows Powershell. https://blogs.msdn.microsoft.com/wmi/2010/01/06/wmic-vs-wmi-powershell-cmdlets


Full disclosure, I have no idea what apache kafka is, thus no experience with using PoSH with it. Yet, that error is something I have seen more than once in customer environments.

postanote
  • 15,138
  • 2
  • 14
  • 25
  • I would argue that even *after* the introduction of `wmic` one *still* could not _easily_ access WMI from the command line. ;) `wmic` syntax is a pain in the rear and has always been. – Ansgar Wiechers Jan 14 '18 at 11:21
  • As for Kafka: it's basically a distributed message queue (similar to e.g. RabbitMQ). – Ansgar Wiechers Jan 14 '18 at 11:25
  • @Ansgar: yep, wmic was and still is the same pain, back when it was intro'd, I dove into it as soon as I could. PoSH just took this to a whole different level and made life more comfortable. Interestingly enough, in some customer environments I've had to deal with, who disabled PoSH (or tried to) I had to fall back to wmic / vbs to get stuff done. So, yep, I still have to deal with it do to customers unwarranted fear of PoSH, despite the number of times I showed them they are not correct in their position. – postanote Jan 15 '18 at 01:33
  • Regarding the Apache Kafka thing. thx, and yep, I did go look at it (youtube and the docs pages) and got that, but I'm an old MSMQ dev, and I did not really see, at least from the docs, what it had over the built-in MSMQ. As with all things, I am sure there is a reasons or two, or just the persons experience and choice. I need to at least spin it up an try it out. – postanote Jan 15 '18 at 01:36