I've created the following PowerShell script to kill a process:
$oProcs = Get-WmiObject Win32_Process -filter "commandline like '%G:\\TCAFiles\\Users\\Admin\\2155\\Unturned.exe%'";foreach ($oProc in $oProcs){Stop-Process $oProc.Handle}
The above script works fine, however when I'm trying to make the script start from Command Prompt it fails.
powershell -Mta -NoProfile -Command "$oProcs = Get-WmiObject Win32_Process -filter "commandline like '%G:\TCAFiles\Users\Admin\2155\Unturned.exe%'";foreach ($oProc in $oProcs){Stop-Process $oProc.Handle}"
This results in the following error:
Get-WmiObject : A positional parameter cannot be found that accepts argument
'%G:\TCAFiles\Users\Admin\2155\Unturned.ex e%'.
At line:1 char:11
+ $oProcs = Get-WmiObject Win32_Process -filter commandline like '%G:\T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand
I'm not sure what this error means or how to resolve it.
Get-Process | Where-Object {$_.Path -eq 'G:\TCAFiles\Users\Admin\ \2155\Unturned.exe'} | Stop-Processor justGet-Process Unturned | Stop-Processcmd.exe. Run it from the PowerShell prompt instead.