{"id":52093,"date":"2009-11-04T00:01:00","date_gmt":"2009-11-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/11\/04\/hey-scripting-guy-can-i-format-a-portable-drive-when-it-is-inserted-into-a-computer\/"},"modified":"2009-11-04T00:01:00","modified_gmt":"2009-11-04T00:01:00","slug":"hey-scripting-guy-can-i-format-a-portable-drive-when-it-is-inserted-into-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-i-format-a-portable-drive-when-it-is-inserted-into-a-computer\/","title":{"rendered":"Hey, Scripting Guy! Can I Format a Portable Drive When It Is Inserted Into a Computer?"},"content":{"rendered":"<p><!-- AddThis Button BEGIN --><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a><!-- AddThis Button END --><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"Readeraidonly\"><font size=\"2\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/font><\/p>\n<p class=\"MsoNormal\">Hey, Scripting Guy! I work with portable USB drives all the time. These are used for backup purposes, for temporary storage, for <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sneakernet\"><font face=\"Segoe\">Sneakernet<\/font><\/a>, and as a means to work with extremely large files that I do not want cluttering up the small hard disk drive on my corporate standard desktop. The problem is that I now have more than a dozen portable USB drives, some of which are continually connected, and others that I shuttle in and out of my computer on an hourly basis to transfer files from one computer to another. (Our IT department has disabled file sharing on our computers, and therefore I cannot simply copy one file from one computer to another. In addition, all file attachments get stripped out of e-mail and so I cannot use e-mail to transfer files either. I am therefore left with sneaker net.) <\/p>\n<p class=\"MsoNormal\">The problem is that, once I have used a portable drive to transfer a file from one computer to another, I do not always delete the file to clean up the drive. As a result some of these drives tend to fill up with useless information. Here is what I currently do: I plug the portable USB drive into my computer, and then navigate to the drive in Windows Explorer to check for files on the drive. If the drive has files, I do a quick format to clean it up. I would love to automate this process. Do you know of a script that will automatically format a portable drive when it is inserted into a computer?<\/p>\n<p class=\"MsoNormal\">&#8212; JM<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello JM, Microsoft Scripting Guy Ed Wilson here. Well this afternoon, the Scripting Wife made me a nice pot of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Earl_Grey_tea\"><font face=\"Segoe\">Earl Grey tea<\/font><\/a> in my little blue tea pot, and even shared one of her <a href=\"http:\/\/en.wikipedia.org\/wiki\/Tim_Tam\">Tim Tams<\/a> with me. I guess she is still excited about her new flat panel monitor for her Windows 7 Ultimate computer. I am listening to &ldquo;Zapatos de Tacon Alto&rdquo; (High-Heeled Shoes) by Jose Feliciano on my Zune. I bought the CD-ROM a couple years ago while I was teaching a VBScript class in Monterrey, Mexico. Anyway, I am reviewing the e-mail in the <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><span><font face=\"Segoe\">scripter@microsoft.com<\/font><\/span><\/a> mail box (we receive several hundred e-mails a week to this alias, and it takes a decent amount of time to go through them all). All in all, it is a terrific afternoon in Charlotte, North Carolina, in the United States&mdash;a fine scripting day! <\/p>\n<p class=\"MsoNormal\">JM, I wrote the MonitorDiskFormatDrive.ps1 script for you. It will detect when a new drive has been added to your system. After the new drive has initialized, the contents of the drive are displayed on your Windows PowerShell console. If there are any files on the portable drive, you will be prompted to format the drive. If no files exist on the drive, it will automatically be formatted. The complete MonitorDiskFormatDrive.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>MonitorDiskFormatDrive.ps1<\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span><font><font face=\"Lucida Sans Typewriter\">#Requires -version 2.0<\/p>\n<p>function Test-IsAdministrator<br>{<br><span>&nbsp;&nbsp;&nbsp; <\/span>&lt;#<br><span>&nbsp;&nbsp;&nbsp; <\/span>.Synopsis<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Tests if the user is an administrator<br><span>&nbsp;&nbsp;&nbsp; <\/span>.Description<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Returns true if a user is an administrator, false if the user is not an administrator<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><br><span>&nbsp;&nbsp;&nbsp; <\/span>.Example<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Test-IsAdministrator<br><span>&nbsp;&nbsp;&nbsp; <\/span>#&gt;<span>&nbsp;&nbsp; <\/span><br><span>&nbsp;&nbsp;&nbsp; <\/span>param() <br><span>&nbsp;&nbsp;&nbsp; <\/span>$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()<br><span>&nbsp;&nbsp;&nbsp; <\/span>(New-Object Security.Principal.WindowsPrincipal $currentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)<br>} #end function Test-IsAdministrator<br><span>&nbsp;<\/span><br>Function Get-IsWindowsXP<br><span>&nbsp;<\/span>{<br><span>&nbsp;&nbsp; <\/span>if( (Get-WmiObject -Class win32_operatingsystem).version<span>&nbsp; <\/span>-gt &#8220;6.1.2600&#8221; ) <br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{ $false }<br><span>&nbsp;&nbsp; <\/span>else { $true }<br><span>&nbsp;<\/span>} #end function Get-IsWindowsXP<\/p>\n<p>Function Get-DriveEvent<br><span>&nbsp;<\/span>{<br><span>&nbsp; <\/span>Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange<br><span>&nbsp; <\/span>$newEvent = Wait-Event -SourceIdentifier volumeChange<br><span>&nbsp; <\/span>Get-DriveContents -path $newEvent.SourceEventArgs.NewEvent.DriveName <br><span>&nbsp;<\/span>} #end function Get-DriveEvent <\/p>\n<p>Function Get-DriveContents ($path)<br><span>&nbsp;<\/span>{<br><span>&nbsp; <\/span>If( (Get-ChildItem -Path $path).count -gt 0) <br><span>&nbsp;&nbsp;&nbsp; <\/span>{<span>&nbsp; <\/span><br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-ChildItem -Path $path<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$in = Read-Host -Prompt &#8220;Drive contains files. Format anyway? y \/ n&#8221;<br><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp; <\/span>if ($in -match &#8220;y&#8221;) { Set-DriveFormat -path $path }<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>if ($in -match &#8220;n&#8221;) { &#8220;Drive will not be formatted. Exiting&#8221; ; exit }<br><span>&nbsp;&nbsp;&nbsp; <\/span>}<br><span>&nbsp;&nbsp; <\/span>Else { Set-DriveFormat -path $path }<\/p>\n<p><span>&nbsp;<\/span>} #end function Get-DriveContents<br><span>&nbsp;<\/span><br>Function Set-DriveFormat($path)<br><span>&nbsp;<\/span>{<br><span>&nbsp; <\/span>&#8220;Formatting drive $path this can take some time &#8230;&#8221;<br><span>&nbsp; <\/span>$drive = Get-WmiObject -Class win32_volume -Filter &#8220;DriveLetter = &#8216;$path'&#8221;<br><span>&nbsp; <\/span>$drive.Format(&#8220;FAT32&#8243;,$true,4096,&#8221;testFormat&#8221;,$false)<br><span>&nbsp;<\/span>} #end function Set-DriveFormat<br><span>&nbsp;<\/span><br># *** Entry Point to Script ***<br>if( -not (Test-IsAdministrator)) { &#8220;This script requires admin rights.&#8221; ; exit }<br>if(Get-IsWindowsXP) { &#8220;This script requires Windows Server 2003 or newer.&#8221; ; exit }<br>&#8220;Watching for new Drive &#8230;&#8221;<br>Get-DriveEvent<\/p>\n<p><\/font><\/font><\/span><\/p>\n<p class=\"MsoNormal\">If you want to format a disk drive, it requires administrator rights. There is no point in running the MonitorDiskFormatDrive.ps1 script if the user does not have administrator rights. To check for these rights, use a function I wrote for the <a href=\"http:\/\/bit.ly\/Win7_ResKit\"><font face=\"Segoe\">Windows 7 Resource Kit<\/font><\/a> called <b>Test-IsAdministrator<\/b>. The <b>Test-IsAdministrator<\/b> function uses the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.security.principal.windowsidentity.getcurrent.aspx\"><font face=\"Segoe\">GetCurrent static method<\/font><\/a> from the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.security.principal.windowsidentity.aspx\"><font face=\"Segoe\">Security.Principal.WindowsIdentity<\/font><\/a> .NET Framework class to determine the current user. After the current user identity is established, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.security.principal.windowsprincipal.isinrole.aspx\"><font face=\"Segoe\">the IsInRole method<\/font><\/a> from the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.security.principal.windowsprincipal.aspx\"><font face=\"Segoe\">Security.Principal.WindowsPrincipal<\/font><\/a> .NET Framework class is used to determine if the current user is an administrator. The <b>Test-IsAdministrator<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">function Test-IsAdministrator<br>{<br><span>&nbsp;&nbsp;&nbsp; <\/span>&lt;#<br><span>&nbsp;&nbsp;&nbsp; <\/span>.Synopsis<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Tests if the user is an administrator<br><span>&nbsp;&nbsp;&nbsp; <\/span>.Description<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Returns true if a user is an administrator, false if the user is not an administrator<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><br><span>&nbsp;&nbsp;&nbsp; <\/span>.Example<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Test-IsAdministrator<br><span>&nbsp;&nbsp;&nbsp; <\/span>#&gt;<span>&nbsp;&nbsp; <\/span><br><span>&nbsp;&nbsp;&nbsp; <\/span>param() <br><span>&nbsp;&nbsp;&nbsp; <\/span>$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()<br><span>&nbsp;&nbsp;&nbsp; <\/span>(New-Object Security.Principal.WindowsPrincipal $currentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)<br>} #end function Test-IsAdministrator<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Because the MonitorDiskFormatDrive.ps1 script relies on the <b>Win32_Volume<\/b> WMI class, the first thing the script does is to determine the version of the operating system (OS) the script is running on. This is because the <b>Win32_Volume<\/b> WMI class does not exist on Windows XP. The OS check is performed in the <b>Get-IsWindowsXP<\/b> function. The <b>Win32_OperatingSystem<\/b> WMI class is used to determine the version of the OS. If the version of the OS is higher than 6.1.2600 (which was the OS version of Windows XP), the script returns <b>false<\/b> to the calling code. If the version of the OS is not greater than 6.1.2600, the function returns <b>true<\/b> to the calling code. The complete <b>Get-IsWindowsXP<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Get-IsWindowsXP<br><span>&nbsp;<\/span>{<br><span>&nbsp;&nbsp; <\/span>if( (Get-WmiObject -Class win32_operatingsystem).version<span>&nbsp; <\/span>-gt &#8220;6.1.2600&#8221; ) <br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{ $false }<br><span>&nbsp;&nbsp; <\/span>else { $true }<br><span>&nbsp;<\/span>} #end function Get-IsWindowsXP<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The <b>Get-DriveEvent<\/b> function is used to create the WMI event that will monitor for a volume change. To do this, the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394516(VS.85).aspx\">Win32_VolumeChangeEvent<\/a> WMI class is used. This WMI class is designed to detect when a volume change event occurs. The event could be a new drive or a drive that was removed from the system. Because of the way the MonitorDiskFormatDrive.ps1 script will be used, it is safe to assume the volume change event that will occur will be a drive-added event. The <b>Register-WmiEvent<\/b> Windows PowerShell cmdlet is used to create the WMI event. The <b>Wait-Event<\/b> Windows PowerShell cmdlet will pause the Windows PowerShell console until an event occurs. This is great for halting the execution of your script when you know that something is about to occur, such as if you are getting ready to insert a USB drive into your computer. When the event occurs, the script will continue and will retrieve the <b>DriveName<\/b> property from the instance of the <b>Win32_VolumeChangeEvent<\/b> WMI class. This is important because when a removable drive is added to my system, a drive letter is assigned to it. The letter is not always the next available drive letter, nor is it always the same drive letter. This is seen here: <\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of the next drive letter assigned\" alt=\"Image of the next drive letter assigned\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1104\/hsg-11-4-09-01.jpg\" width=\"600\" height=\"392\"><\/p>\n<p class=\"MsoNormal\"><br>The complete <b>Get-DriveEvent<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Get-DriveEvent<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>{<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>$newEvent = Wait-Event -SourceIdentifier volumeChange<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>Get-DriveContents -path $newEvent.SourceEventArgs.NewEvent.DriveName <\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>} #end function Get-DriveEvent<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The <b>Get-DriveContents<\/b> cmdlet uses the <b>Get-ChildItem<\/b> Windows PowerShell cmdlet to retrieve the contents of the newly added drive. If the drive has files (in other words, if the count is greater than zero), the <b>Read-Host<\/b> cmdlet is used to prompt the user for permission to format the drive. If the user types &ldquo;y&rdquo;, the <b>Set-DriveFormat<\/b> function is called. If the user types &ldquo;n&rdquo;, the script exits without making any changes. If the drive contains no files, the <b>Set-DriveFormat<\/b> function is called and the drive is formatted. The <b>Get-DriveContents<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Get-DriveContents ($path)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>{<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>If( (Get-ChildItem -Path $path).count -gt 0) <\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>{<span>&nbsp; <\/span><\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-ChildItem -Path $path<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$in = Read-Host -Prompt &#8220;Drive contains files. Format anyway? y \/ n&#8221;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>if ($in -match &#8220;y&#8221;) { Set-DriveFormat -path $path }<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>if ($in -match &#8220;n&#8221;) { &#8220;Drive will not be formatted. Exiting&#8221; ; exit }<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>}<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp; <\/span>Else { Set-DriveFormat -path $path }<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&nbsp;<\/font><\/p>\n<p><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>} #end function Get-DriveContents<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The <b>Set-DriveFormat<\/b> function uses the <b>Win32_Volume<\/b> WMI class, which is documented on <a href=\"http:\/\/bit.ly\/34fcUq\"><font face=\"Segoe\">MSDN<\/font><\/a>. When the script is run, it must be run with administrator rights to format the drive. If it is not run with administrator rights, the script will display a message that indicates administrator rights are required. This is shown here:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image showing administrator rights are required\" alt=\"Image showing administrator rights are required\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1104\/hsg-11-4-09-02.jpg\" width=\"600\" height=\"204\"><\/p>\n<p class=\"MsoNormal\"><br>The complete <b>Set-DriveFormat<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Set-DriveFormat($path)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>{<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>&#8220;Formatting drive $path this can take some time &#8230;&#8221;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>$drive = Get-WmiObject -Class win32_volume -Filter &#8220;DriveLetter = &#8216;$path'&#8221;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>$drive.Format(&#8220;FAT32&#8243;,$true,4096,&#8221;testFormat&#8221;,$false)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>} #end function Set-DriveFormat<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">When the MonitorDiskFormatDrive.ps1 script is run, the script first uses the WMI event to monitor for a new drive event. When the drive event is detected, the drive letter is captured, and the contents of the drive are displayed. If contents are present on the drive, a prompt is used to ask if you wish to format the drive. If you type &ldquo;y&rdquo; for yes, the drive will be formatted. If you type &ldquo;n&rdquo; for no, the script will exit. If the drive is to be formatted, a message that states the drive is being formatted is displayed. The return code from the format method of the <b>Win32_Volume<\/b> WMI class is displayed when the format job is complete. This is shown here:<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of the return code shown when format job is complete\" alt=\"Image of the return code shown when format job is complete\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/november\/hey1104\/hsg-11-4-09-03.jpg\" width=\"600\" height=\"401\"><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">JM, that is all there is to using a WMI event class to monitor for the insertion of a new drive on your computer. WMI Event Week will continue tomorrow when we will talk about&hellip; <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/www.twitter.com\/scriptingguys\/\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/www.facebook.com\/home.php?#\/group.php?gid=5901799452\" target=\"_blank\"><font face=\"Segoe\">Facebook<\/font><\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post them on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<br>&nbsp;<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! I work with portable USB drives all the time. These are used for backup purposes, for temporary storage, for Sneakernet, and as a means to work with extremely large files that I do not want cluttering up the small hard disk drive on my corporate standard desktop. The problem is that [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[42,3,4,45,6],"class_list":["post-52093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-events-and-monitoring","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! I work with portable USB drives all the time. These are used for backup purposes, for temporary storage, for Sneakernet, and as a means to work with extremely large files that I do not want cluttering up the small hard disk drive on my corporate standard desktop. The problem is that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=52093"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=52093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}