- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if the USB device is connected to the system using PowerShell?
To retrieve the USB-connected devices using Powershell, we need to retrieve all the drives using the WMI object or CIM Instance and need to filter the win32_diskdrive class with the USB as shown below.
So basically, USB devices and other removable devices have the drivetype '2'. You can search with the InterfaceType or the DriveType.
WMI commands,
gwmi win32_diskdrive | where{$_.Interfacetype -eq "USB"}
Alternatively,
With the CIM commands,
Get-CimInstance -ClassName Win32_DiskDrive | where{$_.InterfaceType -eq 'USB'}
or
Get-CimInstance -ClassName Win32_LogicalDisk | where{$_.DriveType -eq '2'}
If there is no USB device connected to the system, there will be no output. To retrieve the USB disk on the remote computer use −ComputerName parameter.
Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName TestMachine | where{$_.DriveType -eq '2'}
- Related Articles
- How to eject the USB device from the system using PowerShell?
- How to check if the computer is connected to a domain using PowerShell?
- How to check if a bluetooth device is connected with an Android device using Kotlin?
- How to check if a bluetooth device is connected with Android device?
- How to check if the file is empty using PowerShell?
- How to find the device driver version using PowerShell?
- How to retrieve the Azure subnets connected to the virtual network using PowerShell?
- How to get the load balancers connected to the Azure VM using PowerShell?
- How to check if the date is adjusted by Daylight saving time using PowerShell?
- How to check if the Azure resource group is empty or not using PowerShell?
- How to make a USB device multi-touch enabled
- How to check if a process is exited from the system after executing Stop-Process command in PowerShell?
- How are system calls connected to the operating system?
- How to find device power is connected in android?
- How to check if remote ports are open using PowerShell?

Advertisements