Error: Unable to locate executable file: 'wmic'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
Can someone help me to resolve this problem?
@Terryxxx wmic should be available in C:\WINDOWS\System32\Wbem\WMIC.exe
Can you please restart the agent( and command shell) and this should unblock you.
@nigurr Thanks for your comments. I will try it.
@Terryxxx are you unblocked now?
@ShreyasRmsft Problem is not solved
@Terryxxx did you follow the steps @nigurr has mentioned? Is the wmic.exe present in C:\WINDOWS\System32\Wbem\ on your machine? Did you add it to path and restart the agent process?
Also if you open cmd on the machine and type wmic does it invoke the tool?
@ShreyasRmsft Yes, I have checked my path and verified wmic.exe in C:\WINDOWS\System32\Wbem\ . Please see the follow pic.

@Terryxxx last time I saw this issue was when the build/release definition was overriding the value of Path environment variable. Can you cross check in variable tab to see if Path variables is not getting set
Also one simple check you can do is add a powershell task with the following code:
Write-Host $env:PATH
wmic.exe -somearg
This will tell us for sure.
@ShreyasRmsft I have added a task about it, but it run failed. Following is failed log.
2018-05-22T02:43:28.6520608Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2018-05-22T02:43:28.6521871Z ##[debug]Evaluating: succeeded()
2018-05-22T02:43:28.6522081Z ##[debug]Evaluating succeeded:
2018-05-22T02:43:28.6522378Z ##[debug]=> True
2018-05-22T02:43:28.6522658Z ##[debug]Result: True
2018-05-22T02:43:28.6523220Z ##[section]Starting: PowerShell Script
2018-05-22T02:43:28.6527348Z ==============================================================================
2018-05-22T02:43:28.6527540Z Task : PowerShell
2018-05-22T02:43:28.6527652Z Description : Run a PowerShell script
2018-05-22T02:43:28.6527748Z Version : 1.2.3
2018-05-22T02:43:28.6527838Z Author : Microsoft Corporation
2018-05-22T02:43:28.6527947Z Help : More Information
2018-05-22T02:43:28.6528080Z ==============================================================================
2018-05-22T02:43:28.6910197Z ##[debug]Working directory: 'D:\Agent_work\r1\a'
2018-05-22T02:43:28.6911233Z ##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { $null = [System.Security.Cryptography.ProtectedData] } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; $null = [System.Security.Cryptography.ProtectedData] ; $Error.Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAuHn+VhYXJUOylmUIde4AdgAAAAACAAAAAAAQZgAAAAEAACAAAACvbqoEoJKY1l4bRjYbt8ee4FzRpil7w7ywAZM/oftUhgAAAAAOgAAAAAIAACAAAAAURTOnm3ZrSWFBNtFeIbsjfF2632uRrh0gwjVC4IHfSGAAAAD2jZTRLs1rf8D8Eq5sehRq/t6IC/Es0h7CsicTHsxKA7/4ls3JMqofcXlAwiLs2gVQFAcB+lx6DcppcqlHBAkvdIvwWNtRq1xbBg5KaOd05KCu1ldu5TFX3+EgqNK/f5ZAAAAA4ir1H1k7hx4Awva7kCYnNQ0woyqQFwds+hnOliLwggFBXeZ5VNm1Jk1BYySIlaw7wcFlVdPPngJk953So39acg=='), [System.Convert]::FromBase64String('4HhCi3wwb2E8PFA8a1PtKA=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"
2018-05-22T02:43:28.6912155Z ##[command]. 'C:\Users\superman\AppData\Local\Temp\17cdc4fd-dea3-4406-8899-a606c7206f85.ps1'
2018-05-22T02:43:29.0499961Z D:\Agent_work\r1\a/CN/Artifact1/webApp.runsettings
2018-05-22T02:43:29.2901297Z ##[error]wmic.exe : The term 'wmic.exe' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\superman\AppData\Local\Temp\17cdc4fd-dea3-4406-8899-a606c7206f85.ps1:2 char:1
2018-05-22T02:43:29.3990540Z ##[error]Process completed with exit code 0 and had 1 error(s) written to the error stream.
2018-05-22T02:43:29.4002526Z ##[debug]System.Exception: Process completed with exit code 0 and had 1 error(s) written to the error stream.
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.PowerShellExeHandler.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.
2018-05-22T02:43:29.4005685Z ##[section]Finishing: PowerShell Script
@Terryxxx the failure with wmic was expected.
But i don't see the output for Write-Host $env:PATH
You added the above also right? We just want to confirm whether the PATH variable is getting overridden or not?
If you haven't added Write-Host $env:PATH add it to the script.
You can remove the wmic -somearg line
Also i had specified the order intentionally as i had expected the wmic call to fail but wanted to know content of the PATH variable before wmic was called.
Just run the script with just Write-Host $env:PATH that should tell us all we need to know
@ShreyasRmsft I have added Write-Host $env:PATH. But it does't show any things when it run.

Following is log:
2018-05-22T05:59:33.3102436Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2018-05-22T05:59:33.3204402Z ##[debug]Evaluating: succeeded()
2018-05-22T05:59:33.3213885Z ##[debug]Evaluating succeeded:
2018-05-22T05:59:33.3253092Z ##[debug]=> True
2018-05-22T05:59:33.3278103Z ##[debug]Result: True
2018-05-22T05:59:33.3338892Z ##[section]Starting: PowerShell Script
2018-05-22T05:59:33.3537405Z ==============================================================================
2018-05-22T05:59:33.3537576Z Task : PowerShell
2018-05-22T05:59:33.3537670Z Description : Run a PowerShell script
2018-05-22T05:59:33.3537762Z Version : 1.2.3
2018-05-22T05:59:33.3537866Z Author : Microsoft Corporation
2018-05-22T05:59:33.3537974Z Help : More Information
2018-05-22T05:59:33.3538089Z ==============================================================================
2018-05-22T05:59:33.4100063Z ##[debug]Working directory: 'D:\Agent_work\r1\a'
2018-05-22T05:59:33.4101474Z ##[debug]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "try { $null = [System.Security.Cryptography.ProtectedData] } catch { Write-Verbose 'Adding assemly: System.Security' ; Add-Type -AssemblyName 'System.Security' ; $null = [System.Security.Cryptography.ProtectedData] ; $Error.Clear() } ; Invoke-Expression -Command ([System.Text.Encoding]::UTF8.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String('AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAuHn+VhYXJUOylmUIde4AdgAAAAACAAAAAAAQZgAAAAEAACAAAACYR93E0aSxuKrBOufX65APPCO33riw/wIUpKLoojUqLQAAAAAOgAAAAAIAACAAAAB9kRvn5OttTfe015MaoqIupVw6jbiR97SJrPg4Bh+IoGAAAACkefwSg4+Wv2/iPxQWQSnaUO/fKDaqiGGsxnRPY73FqsGFNqvM50Uo/+Ml1MHhI8UFeJbPq7mW2/0DBiji+hdZOk8f8rgXBmA+XVlhp2K8WBel0suL6Zyg3lD81CED+aZAAAAANh8LzBue2P6Q7uDZM1pQCTk0J3MpDH/elApDLPN7IkTg0PoamtR9BbqOVdMQPMjvF8k32H6PcNBgXQncvO3v0Q=='), [System.Convert]::FromBase64String('g78OSelZMRrPnuegKRGz7Q=='), [System.Security.Cryptography.DataProtectionScope]::CurrentUser))) ; if (!(Test-Path -LiteralPath variable:\LastExitCode)) { Write-Verbose 'Last exit code is not set.' } else { Write-Verbose ('$LastExitCode: {0}' -f $LastExitCode) ; exit $LastExitCode }"
2018-05-22T05:59:33.4102250Z ##[command]. 'C:\Users\superman\AppData\Local\Temp\53ee6e1f-4cd3-421c-8ef7-963999efcb56.ps1'
2018-05-22T05:59:33.7527254Z D:\Agent_work\r1\a/CN/Artifact1/webApp.runsettings
2018-05-22T05:59:33.8076935Z ##[section]Finishing: PowerShell Script
Then it's clear that something in your definition is overriding your system path variable.
But by the way why can't i see the Hello World output from your script?
without the PATH variables value there is no way the task can get the location of wmic and it is bound to fail.
Next step is to identify who is resetting or clearing the PATH variable. Can you send screenshots of your variables section of the build definition.
You can also export your definition to a json file and attach it here or send it to [email protected]
@ShreyasRmsft Thank you very much! I have solved this problem. Cause by I set a "path" variable in definition variables, it reset computer environment path. I have deleted it, it can run successfully.
This is old, but this thread just solved an issue I was dealing with for days! Thank you @ShreyasRmsft. For anyone else who may stumble across this issue...
I was getting the same error as originally reported. On my server VM, I used powershell to Write-Host $env:PATH and it was missing any mention of the C:\WINDOWS\System32\Wbem\ directory.
I have never had to change this, so I found this reference to set the path variables:
https://ginesys.atlassian.net/wiki/spaces/PUB/pages/1900549/How+To+Set+the+PATH+variable+in+environment+variable+in+Windows
Step by step:
C:\Windows\System32\Wbem%SystemRoot%\System32\WbemI queued up the build in TFS, and it ran perfectly.
@michael-gaudet glad it helped :)
Generally Wbem should be included in the PATH by default. Not sure if the image was a custom image or if the stock image was like that.
Most helpful comment
This is old, but this thread just solved an issue I was dealing with for days! Thank you @ShreyasRmsft. For anyone else who may stumble across this issue...
I was getting the same error as originally reported. On my server VM, I used powershell to
Write-Host $env:PATHand it was missing any mention of theC:\WINDOWS\System32\Wbem\directory.I have never had to change this, so I found this reference to set the path variables:
https://ginesys.atlassian.net/wiki/spaces/PUB/pages/1900549/How+To+Set+the+PATH+variable+in+environment+variable+in+Windows
Step by step:
C:\Windows\System32\Wbem%SystemRoot%\System32\WbemI queued up the build in TFS, and it ran perfectly.