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.
Related
I am writing a Powershell script to make a raw copy of a drive and I have been unable to find a way to complete this.
On Linux, I would use 'dd' to perform this copy.
There are a handful of tools that can do this on Windows but none that I can control directly from the command line. (All have GUI interfaces)
Is there a method to make a physical copy of a drive through Powershell?
Thanks.
I've been trying to do this for a while myself and I finally found a good answer.
Git for windows ships with the whole set of GNU core utilities (updated vs what you can find separately) including dd!
Just install Git for Windows or extract the portable version, from there inside of the install directory in git\usr\bin\ you will find the binaries for all of the GNU utils including dd (tested working)
Some further notes on usage in windows since \dev\sda\ isn't a thing:
$DiskDrives = Gwmi Win32_diskdrive | select DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber | Out-GridView -OutputMode Multiple -Title 'Select Source Drive(s)'
$BaseOutputPath = 'D:\'
$DiskDrives | %{
. ('C:\Program Files\Git\usr\bin\dd.exe if={0} of={1} bs={2}' -f $_.DeviceID,(-join($BaseOutputPath,(-
join($Env:ComputerName,$_.Index)),'.img')),$_.BytesPerSector)
}
The included filename logic is just a placeholder, you can replace that parenthetical with a call to Read-Host if you want it to prompt you for the filename/path.
It is a bit annoying but you really do have to use WMI as the values returned by Get-Disk don't seem to work.
You might already know that cygwin on Windows supports some Linux commands including dd. I have used it on several occasions to copy disks and load ISOs to USB and it works perfectly.
Windows 10 comes with linux now. Windows Subsystem for Linux. You can enable it as a feature. You can even get WSL 2 with the real kernel in 1903 & 1909: https://devblogs.microsoft.com/commandline/whats-new-in-the-windows-subsystem-for-linux-september-2020/
Get-CimInstance -ClassName Win32_DiskDrive | Format-List -Property DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber
Following up #Chirishman answer, for Powershell 7.2, The Gwmi may missing from the powershell.
The alternative command to get the DeviceId and other info is available as above.
Then you can use dd if={DeviceId} of=<target_file>.
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.
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)
I have a batch installer that overrides my usb devices drivers.
how can I force my windows to scan for hardware changes using a batch file?
START /WAIT RunDll32.exe Syssetup.dll,UpdatePnpDeviceDrivers
1 The best way I found is:
powershell -windowstyle hidden -command "& {\"rescan\" | diskpart}"
For the detail, you can refer to this link :"Use the rescan command to rescan all I/O buses and cause any new disks that have been added to the computer to be discovered."
For Windows 2008/7 and above, the powershell and diskpart is shipped with OS.
Or just run it without powershell:
echo rescan | diskpart
2 The other way is use the MS command line tool, Devcon, which you have to download it first
You can use it to do a lot of things, including enable/disable/rescan all kind of device(not only disk), update device driver, ... even on the remote machine.
You also can see the source code of it in this link
Windows 10 ships with PnPUtil.exe. Run pnputil.exe /scan-devices from administrative command prompt.
https://serverfault.com/a/1060172/365042
Is there any command in windows which can give full path of the process running
tasklist does not give full paths. I do not want to use task manager
The tlist tool is not distributed with the Windows Resource Kit anymore (it's been superseded by tasklist), but is able to list the full path of each process.
You can fetch a copy from the download center.
Now can do it using powershell:
PS C:\> gwmi win32_process | select CommandLine | select-string -pattern "process-name"