Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define the mappings for DeviceID to SourceDirectory and TargetDirectory
- $deviceMappings = @{
- "USBSTOR\DISK&VEN_FAKE&PROD_FLASH_DRIVE&REV_2.10\SN1234567890&0" = @{
- SourceDirectory = "DataToSync"
- TargetDirectory = "C:\Backup\USBFlashDrive"
- }
- "USBSTOR\DISK&VEN_GENERIC&PROD_USB_DISK&REV_6.50\4&ABCDEF12&0&_&0" = @{
- SourceDirectory = "Test"
- TargetDirectory = "C:\Flash\GeneralUDisk\Test"
- }
- "USBSTOR\DISK&VEN_VIRTUAL&PROD_STORAGE&REV_0001\ZZ9012345678&0" = @{
- SourceDirectory = "ImportantDocs"
- TargetDirectory = "C:\Archive\ST8GBDrive"
- }
- }
- # Get the USB devices and create custom objects with the required properties
- $usbDevices = Get-PnpDevice | Where-Object { $_.DeviceID -like "USBSTOR*" }
- $customObjects = foreach ($device in $usbDevices) {
- $deviceId = $device.DeviceID
- $status = $device.Status
- if ($deviceMappings.ContainsKey($deviceId)) {
- [PSCustomObject]@{
- DeviceID = $deviceId
- SourceDirectory = $deviceMappings[$deviceId].SourceDirectory
- TargetDirectory = $deviceMappings[$deviceId].TargetDirectory
- }
- } else {
- [PSCustomObject]@{
- DeviceID = $deviceId
- SourceDirectory = "NotMapped"
- TargetDirectory = "NotMapped"
- }
- }
- }
- # Export the custom objects to a CSV file
- $customObjects | Export-Csv -Path "C:\Users\J2897\DeviceMapping.csv" -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement