3

I want to run this command and capture the output:

fsutil fsinfo volumeInfo C:

But unless I open a cmd.exe manually "as administrator", it won't execute the command for some absurd reason. This means that it cannot be run from PHP CLI.

What is a different, non-stupid way of getting this information? And why is the fsutil command requiring administrative privileges?

Please note that I've spent ages of my life just trying to get PHP CLI to run as administrator for this kind of thing to work, but it never does work. All "workarounds" I've heard are insane and make my skin crawl.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Advit
  • 51
  • 4
  • 1
    WMI probably also has the information you seek. – Daniel B Oct 19 '22 at 18:40
  • What information are you looking for, specifically? PowerShell's `Get-WMIObject -Class Win32_LogicalDisk` can provide at least some of the information that `fsutil` does, and doesn't appear to require an elevated PowerShell session. – Jeff Zeitlin Oct 19 '22 at 18:48
  • @JeffZeitlin "NTFS" or "exFAT", for example. – Advit Oct 19 '22 at 18:52
  • So you're _just_ looking for the filesystem type? In that case, you can either use the answer that @Tonny provided below (which works in CMD), or, if you can use PowerShell, `(Get-WMIObject -Class Win32_LogicalDisk -Filter "Caption='$drive'").FileSystem` will return the filesystem type for the drive `$drive` (e.g., if `$drive = "D:"`. it will give you the filesystem (e.g., `NTFS` of drive D:). – Jeff Zeitlin Oct 19 '22 at 18:58
  • If you want to do this for a computer _other_ than the one the command is running on, PowerShell can do it by adding `-ComputerName $Comp` inside the parentheses in the command above (e.g., if you want to get the filesystem on drive C: of computer RemoteBox, `(Get-WMIObject -ComputerName RemoteBox -Class Win32_LogicalDisk -Filter "Caption='C:'").FileSystem`) – Jeff Zeitlin Oct 19 '22 at 19:02

3 Answers3

5

wmic doesn't require administrator elevation.

To get all disks :

wmic volume get DriveLetter,FileSystem

To list one disk (D) :

wmic volume where DriveLetter='D:' get FileSystem
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • 1
    Essentially the same as my answer, but this is cleaner as it filters directly for the desired drive. (I totally forgot you can use WHERE in WMIC queries). – Tonny Oct 20 '22 at 08:16
  • 1
    https://stackoverflow.com/questions/57121875/what-can-i-do-about-wmic-is-deprecated This tool is deprecated. – Ismael Miguel Oct 20 '22 at 11:42
  • The WMI interface will never be deprecated - it's used in too many tools. Just another attempt by Microsoft to push people to using PowerShell. – harrymc Oct 20 '22 at 13:55
  • 1
    @harrymc It may never be _removed_, but it _has_ been deprecated. (They've put a notice on it saying "please don't use me".) – wizzwizz4 Oct 20 '22 at 16:51
  • @harrymc and yet they're fine with WSL. Go figure. – Mark Ransom Oct 20 '22 at 17:46
  • This is rich - people are downvoting this because they are worried that WMIC might disappear in a decade or two. Microsoft has been trying to move away from CMD/DOS for about 30 years and got nowhere, probably mostly because of corporate customers. WMIC is in the same class - a very much-used utility. – harrymc Oct 20 '22 at 19:23
3

Here is how to achieve the same action in WMI using PowerShell since wmic is being deprecated. To get just D:, use the following command (Get-WmiObject).

Get-WmiObject -Class Win32_Volume | Where-Object {$_.DriveLetter -eq "D:"}

To get all drives, use the following command:

Get-WmiObject -Class Win32_Volume

If you want to see less output and find out just the file system associated with each drive, you can also use this command to select only the drive letter and filesystem properties from the volume objects:

Get-WmiObject -Class Win32_Volume | Select-Object -Property DriveLetter,FileSystem
Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
saltthehash
  • 171
  • 4
2

Try wmic volume get caption,filesytem
And filter the output for the drive-letter that you want.

Does not require admin rights.

Tonny
  • 29,601
  • 7
  • 52
  • 84
  • 1
    https://stackoverflow.com/questions/57121875/what-can-i-do-about-wmic-is-deprecated This tool is deprecated. – Ismael Miguel Oct 20 '22 at 11:43
  • 1
    @IsmaelMiguel I know very well that WMIC is depreciated. But it is still the best/easiest way to get something done in many cases. Microsoft is forcing PowerShell down our throats, but PowerShell is tricky to get right (syntax wise and finding out how to get the results you need) and it is relatively slow to run as sub-process. It has a lot of overhead (which doesn't really matter if you have a whole script in PS, but for a one-liner it does), while WMIC is pretty lightweight. Also: There are several different PS/.Net combinations. Which one are you using and which one do your customers have? – Tonny Oct 20 '22 at 11:54
  • The "problem" is that *you* know, but others probably don't. I'm not commenting on how good or bad it is. I'm just pointing it out, for people that come here looking at the answers. Either now or in the future. Being deprecated is something that's important to know, when reading this answer. – Ismael Miguel Oct 20 '22 at 12:03