Files
Scripts_Powershell/usb.ps1
2020-05-30 15:10:42 +02:00

50 lines
1.4 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Get-CimClass -ClassName Win32_DiskDrive
#$usb = GET-WMIOBJECT query "SELECT * from win32_diskdrive where InterfaceType = 'USB'"
$usb = GET-WMIOBJECT win32_diskdrive | Where { $_.InterfaceType -eq 'USB' }
$usb
#If ($usb.model -ne "Kingston DataTraveler 3.0 USB Device"){
If ($usb.model -eq "USB Device") {
Write-host "USB Device inserted"
}
#Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange
#$newEvent = Wait_Event -SourceIdentifier volumeChange
#$newEvent
###################
Get-WmiObject Win32_DiskDrive | ForEach-Object {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | ForEach-Object {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | ForEach-Object {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = $disk.Size
DiskModel = $disk.Model
Partition = $partition.Name
RawSize = $partition.Size
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = $_.Size
FreeSpace = $_.FreeSpace
}
}
}
}
$drives = Get-PSDrive
$drives
foreach ($root in $drives.root){
$root
}
# |{}