How can get Hard Disk Information Using CMD - windows

I am use this command for finding hard disk in formation "wmic diskdrive" but i insert a external device like hard disk or pan drive, this command is provide information of external hard disk or pan drive. so how can find internal hard disk information where system window installed.

It is off topic here , though you can get the info using following cmd
wmic logicaldisk
or ,
diskpart then list volume

The PowerShell way is:
PS C:\> $Disk = Get-WmiObject -Class Win32_logicaldisk -Filter "DeviceID = 'C:'"
PS C:\> $DiskPartition = $Disk.GetRelated('Win32_DiskPartition')
PS C:\> $DiskDrive = $DiskPartition.GetRelated('Win32_DiskDrive')
PS C:\> $DiskDrive.Size
1024203640320
This is nicely explained here.
But the original question was about how to do this with CMD.
C:\>wmic diskdrive get model,name,size
Model Name Size
SAMSUNG MZVLB1T0HALR-000L7 \\.\PHYSICALDRIVE0 1024203640320
Generic- SD/MMC USB Device \\.\PHYSICALDRIVE1
Given a choice, I prefer to use the PowerShell method, starting from the drive letter and working up to the physical disk. It's rather verbose but it gives a unique answer, and requires no knowledge of the system. (Some devices have many physical disks and it can get confusing.)

"find internal hard disk information where system window installed."
wmic logicaldisk where caption="%systemdrive%" get /value
Note: logicaldisk is a partition on an physical drive (the only one, if you are lucky, but there may be more partitions on the same physical drive)

Related

Can I access a USB drive by its name?

I have a Powershell script on my windows machine that needs to access data from a USB drive. It reads a file from the USB stick and does its thing. I need to do this over many machines. The problem is that the USB drive can appear under different drive letters, depending on the machine I insert the stick into. My USB drive is called "USBData". Is there a way to reliably access the USB drive using its name rather than its drive letter?
$driveletter = (Get-Volume -FileSystemLabel "USBData").DriveLetter
echo "${driveletter}:\"
You can do a:
(Get-WMIObject Win32_Volume | ? { $_.Label -eq 'USBData' }).DriveLetter
to get the Drive and then execute relative to it. Something like:
$USBDrive = (Get-WMIObject Win32_Volume | ? { $_.Label -eq 'USBData' }).DriveLetter
$ProcessFullPath = "$USBDrive\Executable.exe"
Start-Process $ProcessFullPath

Check mapped drives in .bat file

I want to list all my disks with a .bat file to check if a network disk is connected or not.
I've made the next .bat file that works and shows me the physical and logial disks.
#echo off
wmic logicaldisk get caption,drivetype,providername
pause
exit
The question is: How do I check if it's connected or not? It possible to autoconnect in case the mapped disk is disconnected?
Thanks!
You can modify the pattern in the sample below to return Connected or Disconnected mapped drives (or remove the piped portion all together to return all connections). As for reconnecting the drives, if they're disconnected, doesn't that mean its a network issue, since windows automatically reconnects them when the connection is available?
Batch Script (CMD):
wmic netuse list brief | find "Connected"
Powershell:
wmic netuse list brief | Select-String -Pattern "Connected"

CMD command to check connected USB devices

I would like to obtain by a command prompt a list of all USB devices connected to my computer (O.S. Windows 10). I've googled to find such a command, but all results seems useless to me or worse workless. Does anybody know how can I do that?
Thank you
You can use the wmic command:
wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value
With powershell, you can use the command :
Get-PnpDevice -PresentOnly | Where-Object { $_.InstanceId -match '^USB' }
You could use wmic command:
wmic logicaldisk where drivetype=2 get <DeviceID, VolumeName, Description, ...>
Drivetype 2 indicates that its a removable disk.
pnputil /enum-devices /connected /class USB
This requires Windows 10 1903 or higher. List of possible flags
you can download USBview and get all the information you need. Along with the list of devices, it will also show you the configuration of each device.

Double driver export script

I'm terrible at scripting, so I would like some help with a script which does the following:
a wmic query:
wmic computersystem get model
Latitude E7450
creates a folder in the root using the query output without spaces:
Latitude_E7450
Then run double driver to backup all the drivers and storing them in the newly created folder:
ddc b /source:"c:\Windows" /target:"c:\Latitude_E7450"
You can get name for the target folder from the WMI Model using powershell, assuming WMI returns this (some OEM units don't),
$dirName = (Get-WmiObject -Class win32_computersystem).Model
Then you can call Double Driver,
& ddc.exe b /source:"C:\Windows" /target:"C:\$dirName"
For a pure powershell solution, see for example this post from Mikael Nyström, "PowerShell is King – Export drivers from Windows"
Export-WindowsDriver -Destination "C:\Drivers\$((Get-WmiObject -Class win32_computersystem).Model)" -Online
This requires Windows 6.3 at least (8.1 or 2012 R2), so use Double Driver for Win 7, if you can still find it. For even more bells and whistles, see "Building Configuration Manager Driver Packages for Windows 7 with PowerShell and Double Driver".

How can I use `wmic` in a Windows PE script?

I'm trying to determine the computer model (e.g., "Optiplex 9010") in a batch script running in the context of Windows PE 3.1. When running Windows proper, I can do this using wmic csproduct or wmic bios but neither of these return any data when running Windows PE. (This also seems to be true of most or all other classes.)
I've already installed the winpe-wmi.cab package to support WMI. Using wmic path instead of an alias makes no difference.
How can I make my wmic commands work?
It turns out that most wmic commands, including both wmic csproduct and wmic bios, will work if you install the winpe-scripting.cab package in addition to the winpe-wmi.cab package.

Resources