50 lines
1.4 KiB
PowerShell
50 lines
1.4 KiB
PowerShell
# 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
|
||
}
|
||
# |{} |