En effet, j'ai besoin de localiser un lecteur spécifique (une clé USB) ayant de surcroit un nom de volume spécifique (la bonne Clé USB, celle qui ne nomme "Cruizer").
Voici un petit script vraiment très utile que j'ai trouvé ici sur PowerShell.Com.
Merci à Brian Hagerty pour ce post vraiment très utile.
# DESCRIPTION: Checks to see if a USB logical drive is present, if so, then alerts the user and rechecks function CheckFor-USBDrive () { # Gets the USB logical drive $USBDrive_Present = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {($_.DriveType -eq 2) -and ($_.DeviceID -ne "A:")} $count = 0 # If a USB drive is present then sound 'alert' five times and show message box while($USBDrive_Present) { Write-Host -NoNewline "`a`a`a`a`a" # Alert tone (5) # Checks whether this is the first time the message box is displayed. if($count -lt 1) { Show-MessageBox "ATTENTION: USB Drive" "`nThere is a USB Flash Drive present. Please remove then click OK." $count++ } # If its not the first time then display a different message else { Show-MessageBox "ATTENTION: USB Drive" "`nThe USB Flash Drive was not removed. Please remove then click OK." } # Recheck for USB flash drive, then continue while loop if applicable $USBDrive_Present = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {($_.DriveType -eq 2) -and ($_.DeviceID -ne "A:")} } }
Aucun commentaire:
Enregistrer un commentaire