1

I'm running a PowerShell script with the following:

Copy-Item -Path d:\Deploy\Scripts\content\PC-IP -Destination c:\installs -recurse -Force Copy-Item -Path d:\Deploy\Scripts\content\Mobile-license -Destination c:\installs -recurse -Force

This works great, but instead of hard-coding the D drive (USB drive) I was wondering if there is a way to automatically detect the USB drive letter. Something like this: %usbdrive%

I have several desktops and laptops that use D, E and F as the USB drive letter.

Thank you, Justin

Nacho
  • 1,104
  • 1
  • 13
  • 30
Justin
  • 11
  • 1
  • duplicate of: http://stackoverflow.com/questions/10634396/how-do-i-get-the-drive-letter-of-a-usb-drive-in-powershell – Eduard Uta Apr 07 '16 at 19:23
  • try this `$drives = gwmi win32_volume -filter 'drivetype = 2' | % {$_.driveletter[0]}` or this `$drives = [System.IO.DriveInfo]::GetDrives() | ? drivetype -eq 'Removable' | % {$_.tostring()[0]}` then you can `$drives | % {if (test-path $($_ + ":\deploy\scripts\content\pc-ip")) {$_}}` – Anthony Stringer Apr 07 '16 at 19:44
  • Anthony, Can you show me how I would incorporate my copy-item script into this – Justin Apr 08 '16 at 16:06

0 Answers0