CheckFor-USBDrive


posted by Brian Hagerty
11-13-2009

Downloads: 431
File size: 1.1kB
Views: 1,973

Embed
CheckFor-USBDrive
  1. # DESCRIPTION: Checks to see if a USB logical drive is present, if so, then alerts the user and rechecks 
  2. function CheckFor-USBDrive () { 
  3.     # Gets the USB logical drive  
  4.     $USBDrive_Present = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {($_.DriveType -eq 2) -and ($_.DeviceID -ne "A:")} 
  5.     $count =
  6.      
  7.     # If a USB drive is present then sound 'alert' five times and show message box 
  8.     while($USBDrive_Present) { 
  9.         Write-Host -NoNewline "`a`a`a`a`a" # Alert tone (5) 
  10.         # Checks whether this is the first time the message box is displayed. 
  11.         if($count -lt 1) { 
  12.             Show-MessageBox "ATTENTION: USB Drive" "`nThere is a USB Flash Drive present. Please remove then click OK." 
  13.             $count++ 
  14.         
  15.         # If its not the first time then display a different message 
  16.         else { Show-MessageBox "ATTENTION: USB Drive" "`nThe USB Flash Drive was not removed. Please remove then click OK."
  17.          
  18.         # Recheck for USB flash drive, then continue while loop if applicable 
  19.         $USBDrive_Present = Get-WmiObject -Class Win32_LogicalDisk | Where-Object {($_.DriveType -eq 2) -and ($_.DeviceID -ne "A:")} 
  20.     

Checks to see if a USB logical drive is present, if so, then alerts the user and rechecks. Great for use in Windows Logoff scripts.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.