Bob.
foreach ( $entry in $SQLQuery )
{
if ($entry.pathtofile -like '*\*')
{
$currentPath = $entry.currentPath + (split-path $entry.pathtofile -parent) + '\'
$containerPath = $entry.containerPath + (split-path $entry.pathtofile -parent) + '\'
$pathtofile = Split-Path $entry.pathtofile -Leaf
$tmp = $currentPath
for( $i = $currentPath.split("\").count; $i -gt 7; $i-- ){
$tmp = $tmp | split-path
$tmp
## Begin.
[array]$subOne = Get-ChildItem $currentPath
if ( $subOne.count -gt 1 )
{
Get-ChildItem $currentPath | select Name, FullName, @{Name="Mbytes";Expression={$_.Length / 1Mb}} | foreach {
if ($_.name -ne $pathToFile )
{
if(!(Test-Path -Path $entry.containerPath))
{
Copy-Item $entry.currentPath -Destination $entry.containerPath -recurse
}
if(Test-Path -Path $entry.containerPath)
{
$value = $_.Fullname + ',' + $_.Mbytes
Add-Content c:\temp\Content-Cleanup.csv -value $value
Remove-Item $_.FullName -Recurse
}
}
}
}
## Begin.
[array]$subTwo = Get-ChildItem $tmp
if ( $subTwo.count -gt 1 )
{
Get-ChildItem $tmp | select Name, FullName, @{Name="Mbytes";Expression={$_.Length / 1Mb}} | where { $_.FullName -notlike $r.TrimEnd('\') -and $_.FullName -ne $currentPath.TrimEnd('\') } | foreach {
if(!(Test-Path -Path $entry.containerPath))
{
Copy-Item $entry.currentPath -Destination $entry.containerPath -recurse
}
if(Test-Path -Path $entry.containerPath)
{
$value = $_.Fullname + ',' + $_.Mbytes
Add-Content c:\temp\Content-Cleanup.csv -value $value
Remove-Item $_.FullName -Recurse
}
}
}
$r = $tmp
}
}
else
{
$currentPath = $entry.currentPath
$containerPath = $entry.containerPath
$pathtofile = $entry.pathtofile
$currentPath
[array]$sub = Get-ChildItem $currentPath | where{!$_.PsIsContainer}
## Begin.
if ( $sub.count -gt 1 )
{
Get-ChildItem $currentPath | select name, FullName, @{Name="Mbytes";Expression={$_.Length / 1Mb}} | foreach {
if ( $_.name -ne $pathToFile )
{
if(!(Test-Path -Path $containerPath))
{
Copy-Item $currentPath -Destination $containerPath -recurse
}
if(Test-Path -Path $containerPath)
{
$value = $_.Fullname + ',' + $_.Mbytes
Add-Content c:\temp\Content-Cleanup.csv -value $value
Remove-Item $_.FullName
}
}
}
}
}
}