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
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
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
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^)
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
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.
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)
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.
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
10 people are following this question.