question

oemScript avatar image
0 Votes"
oemScript asked AndreasBaumgarten edited

How to code this powershell script?

I would like to know on filling USB (32 GB) with following image by copy and paste many times using powershell script. Does anyone have any suggestions? Thanks in advance Image location C:\samples.jpg

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

Hi @oemScript-8271 ,

maybe this helps.

 $targetpath = "<target drive>"
 $sourcefile = "samples.jpg" # Just put the sourcefile in the same folder with the script
 $copies = 15
 $counter = 0
 do {
     Copy-Item -path $sourcefile -Destination "$targetpath\$counter$sourcefile"
     $counter++ 
 } until ($counter -eq $copies)


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

oemScript avatar image
0 Votes"
oemScript answered AndreasBaumgarten edited

For target drive, I would like to know on what should be filled in for F: Drive

$targetpath = "F:", correct?

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you want to copy the files directly on the USB drive (F:) it should be $targetpath = "F:" or $targetpath = "F:\" (I haven't tested it with a drive, just with a folder on my MacBook)


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·
IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

You may try this

 $drive = 'F:'
 $image = 'C:\samples.jpg'
 $times =[int][Math]::Floor((Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = '$drive'").FreeSpace/(Get-Item -Path $image).Length)
 for($i=0;$i -le $times; $i++)
 {
     Copy-Item -Path $image -Destination $drive\samples$i.jpg  
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

oemScript avatar image
0 Votes"
oemScript answered AndreasBaumgarten edited

Referring to following image, I would like to know on what wrong it is.

Do you have any suggestions?
Thank you very much for any suggestions (^v^)


      $targetpath = "F:"
      $sourcefile = "D:\Sample.bmp" # Just put the sourcefile in the same folder with the script
      $copies = 15
      $counter = 0
      do {
          Copy-Item -path $sourcefile -Destination "$targetpath\$counter$sourcefile"
          $counter++ 
      } until ($counter -eq $copies)

82641-error.png




error.png (12.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Your destination path "$targetpath\$counter$sourcefile" is like "F:\5D:\Sample.bmp". Just remove the driver letter of the source file from your destination path.

1 Vote 1 ·

The $sourcefile should be just the name of the file and not the path.

 $sourcefile = "sample.jpg"


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·
oemScript avatar image
0 Votes"
oemScript answered

Thanks, to everyone very much for suggestions (^v^)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.