Hi guys!
I spent a lot of time trying to write and improve this script but there are Always some problems...
Look at this:
Import-Module "C:\Script\Get-Report.psm1"
Function Get-Filter{
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True,Position=0)]$A,
[Parameter(Mandatory=$True,Position=1)][array]$Type
)
$Counter=0
If($Type -contains $A.Extension){
$Counter++
}
elseif($Type -contains $A.Name){
$Counter++
}
elseif($A.Name.StartsWith("~$")){
$Counter++
}
if($Counter -gt 0){
return $true
}
}
function Change($i){
$split=$i.Attributes -split(', ')
$join=($split | where{$_ -ne "Hidden"}) -join(', ')
if($join -eq ""){
$i.Attributes = [System.IO.FileAttributes]::Normal
}
else{
$i.Attributes = $join
}
return $i.Attributes
}
function Hide_And_Temp{
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True,Position=0)]$Search,
[Parameter(Mandatory=$True,Position=1)][array]$Type,
[Parameter(Mandatory=$True,Position=2)]$Kind
)
$FNE=@()
$Car=@()
$Ele=@()
#$Att=@()
Dir $Search -Force -Recurse|
Where-Object {Get-Filter $_ $Type } |
Sort-Object -Property Name |
ForEach-Object{
if($_.Attributes -match "Hidden"){
$_.Attributes=Change($_)
}
$FNE += $_.fullname
$Car += ($_.Directory -replace ":","$")
$Ele += $_.Name
#$Att += $_.Attributes
}
For($i=0; $i -lt $Car.Count; $i++){
$Dest=$Folder,$Car[$i] -join('\')
if(!(Test-Path $Dest)){
New-Item -Path $Dest -ItemType directory
}
Move-Item -Path $FNE[$i] -Destination "$Dest\$Ele[$i]" -Force
}
Return $FNE
}
$Today = Get-Date -Format "dd-MMM"
$Kind= "Temporary"
$Folder= "C:\Estinto\$Today\$Kind"
$Type=@(".$$$",".$YY$",".tmp",".temp",".DS_Store",".part",".wbk","Thumbs.db" )
$Search= "C:\Test"
$FNE=@()
$FNE += Hide_And_Temp $Search $Type $Kind
$drives=foreach($path in $FNE){
$prophash = @{
Nome= split-path $path -leaf
Percorso = $path
}
New-Object PSObject -Property $prophash
}
Get-Report $drives $KindWhat do you get? (Well maybe you must have the module Get-Report to have a complete vision but try anyway)
The Function Hide_and_temp must take only temporary files, remove the hidden attribute if existent, and move all this elements into a new folder.
Please, try... tell me what's wrong... i'm going mad!!!
Thanks in advance
A