If you are happy to update the target path each time, then all you need to do is add a counter into your script, then check its less than 100 each time through the for loop.
$sourcePath = "/sitecore/media library/Default Website"
$targetPath = "/sitecore/media library/dev"
$counter = 0
Get-ChildItem $sourcePath -Recurse | ForEach-Object {
$name = $_.Name
if((![string]::IsNullOrEmpty($name)) -and ($counter -lt 100) -and ($_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder)))
{
Move-Item -Path $_.ItemPath -Destination $targetPath;
Write-Host "Item moved to: "$_.ItemPath;
$counter+=1
}
else
{
Write-Host "Couldn’t move Item because empty name: " $_.Id;
}
}
Note I also added in a check to confirm the templateId for the item is not a folder.
When testing out powershell scripts in sitecore, it is useful to first do a test run to see what would be effected without moving the items themselves.
The script below, splits the actions into two methods Find-MediaItems and Move-MediaItems. You can then call Find-MediaItems first and output the results to table.
If you are happy with what is going to be moved, you then need to uncomment the line #MoveItem($item), and comment out the line above.
function Find-MediaItems {
$items = Get-ChildItem -Path $sourcePath.Paths.FullPath |
Where-Object { ($_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder) }
foreach($item in $items) {
$item;
#MoveItem($item)
}
}
function MoveItem($item)
{
$name=$item.Name
if((![string]::IsNullOrEmpty($name)) -and ($counter -lt 100)))
{
Move-Item -Path $_.ItemPath -Destination $targetPath;
Write-Host "Item moved to: "$_.ItemPath;
$counter+=1
}
else
{
Write-Host "Couldn’t move Item because empty name: " $_.Id;
}
}
$props = @{
InfoTitle = "Media items to move"
InfoDescription = "Lists all media items that the script will eventually move"
PageSize = 25
}
Find-MediaItems |
Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} },
@{Label="Updated"; Expression={$_.__Updated} },
@{Label="Updated by"; Expression={$_."__Updated by"} },
@{Label="Created"; Expression={$_.__Created} },
@{Label="Created by"; Expression={$_."__Created by"} },
@{Label="Path"; Expression={$_.ItemPath} }
Close-Window
The above is something I found myself when in similar situation to you, then have edited to suit over time (cant recall original source).