How to code this powershell script?

oemScript 81 Reputation points
2021-03-29T23:09:47.887+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 96,036 Reputation points MVP
    2021-03-29T23:34:37.817+00:00

    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

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. oemScript 81 Reputation points
    2021-03-30T00:44:02.747+00:00

    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^)


  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,491 Reputation points Microsoft Vendor
    2021-03-30T01:46:31.617+00:00

    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.

    0 comments No comments

  3. oemScript 81 Reputation points
    2021-03-30T04:25:13.127+00:00

    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


  4. oemScript 81 Reputation points
    2021-03-30T06:52:09.073+00:00

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

    0 comments No comments