New
#1311
In what context shouldfor /f
be used?
It will probably not work.
well, it works.
IF the string does not includeCode:C:\Users\jbcarreon123>for /F "tokens=*" %1 in ('echo test') do (echo %1 | findstr /v /c:"[") C:\Users\jbcarreon123>(echo test | findstr /v /c:"[" ) test C:\Users\jbcarreon123>for /F "tokens=*" %1 in ('echo [') do (echo %1 | findstr /v /c:"[") C:\Users\jbcarreon123>(echo [ | findstr /v /c:"[" ) C:\Users\jbcarreon123>for /F "tokens=*" %1 in ('echo [================100%===============]') do (echo %1 | findstr /v /c:"[") C:\Users\jbcarreon123>(echo [ 100% ] | findstr /v /c:"[" ) C:\Users\jbcarreon123>for /F "tokens=*" %1 in ('echo [test]') do (echo %1 | findstr /v /c:"[") C:\Users\jbcarreon123>(echo [test] | findstr /v /c:"[" ) C:\Users\jbcarreon123>[
, then it proceeds.
It will work only after the whole operation has been completed.
It will not show the progress while the operation is in progress.
Your code can be somewhat simplified by usingswitch
instead ofif
+elseif
+else
as shown below:
Code:PowerShell GWMI -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage^|FT -A FriendlyName,@{l='MediaType';e={switch($_.MediaType){0{'USB'};3{'HDD'};4{'SSD'}}};A='Right'}
Run the following and post the output:
Code:PowerShell GWMI -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage^|Select FriendlyName,MediaType