a.t.
a.t.

Reputation: 2808

How to get the windows drive in Powershell?

How can one get the drive name that contains the current windows installation in Powershell?

I thought about looping through the DeviceId output of get-wmiobject -class win32_logicaldisk and scanning each drive that is returned whether it contains folder <drive name>/Windows/System32/.

However I think there is a less convoluted way of finding the drive (which might also be less error prone in case of multiple windows installations on different drives on a single pc).

Upvotes: 2

Views: 2538

Answers (1)

Paolo
Paolo

Reputation: 26074

You can use:

(Get-WmiObject Win32_OperatingSystem).SystemDrive
# C:

reference https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem

Upvotes: 5

Related Questions