Albiz849
26-11-2013, 08:27
Ciao!
Sto scrivendo uno script che mi sposta alcuni file in una unica cartella.
Vorrei però fare in modo che se un file ha l'attributo Nascosto (può averne anche altri ma non voglio toccarli) quando viene spostato perde solo questa proprietà. Io ho provato ad informarmi e a fare qualche prova e ne è uscito questo:
$Move=@()
$Att=@{}
$Today = Get-Date -Format "dd-MM"
$Folder= "C:\Estinto\$Today"
if(!(Test-Path $Folder)){
New-Item -Path $Folder -ItemType directory
}
$Ent=Get-ChildItem "C:\Test" -Recurse -Force -include *.$YY$, *.tmp, *.temp, *.DS_Store, *.part, ~$*, Thumbs.db
foreach($i in $Ent){
if($i.mode -match "h"){
$Att[$i]=$i.Attributes
$Att[$i]=$Att[$i] | where{$_ -ne "Hide"} #questo non va
$i.Attributes = $Att[$i]
}
$Move=$Move+$i.fullname
Move-Item $i.fullname -Destination $Folder
}
$Move= $Move | sort{Split-Path( $_ ) -leaf}
$drives = foreach ($path in $Move) {
$prophash = @{
Nome= split-path $path -leaf
Percorso = $path
}
#create a new object from the property hash
New-Object PSObject -Property $prophash
}
#embed the style in the html header
$head = @'
<Title>Deleting Temp Report</Title>
<style>
body
{
background-color:#FFFFFF;
font-family:Verdana;
font-size:12pt;
}
td, th
{
border:1px solid blue;
border-collapse:collapse;
}
th
{
color:white;
background-color:green;
}
table, tr, td, th { padding: 5px; margin: 0px }
table { margin-left:50px; }
</style>
'@
#create an xml document from the HTML fragment
[xml]$html = $drives | ConvertTo-Html -fragment
#check each row, skipping the TH header row
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$class = $html.CreateAttribute("class")
}
#create the final report from the innerxml which should be html code
$body = @"
<H1>Deleting Temp Report for $Folder</H1>
$($html.innerxml)
"@
#put it all together
$Name = "Deleting Temp " + $Today
ConvertTo-HTML -head $head -PostContent "<br><i>$(Get-date)</i>" -body $body |
Out-File "C:\Log\$Name.html" -Encoding ascii
Invoke-Item "C:\Log\$Name.html""
qualche idea per scriverlo meglio?
Grazie
A
Sto scrivendo uno script che mi sposta alcuni file in una unica cartella.
Vorrei però fare in modo che se un file ha l'attributo Nascosto (può averne anche altri ma non voglio toccarli) quando viene spostato perde solo questa proprietà. Io ho provato ad informarmi e a fare qualche prova e ne è uscito questo:
$Move=@()
$Att=@{}
$Today = Get-Date -Format "dd-MM"
$Folder= "C:\Estinto\$Today"
if(!(Test-Path $Folder)){
New-Item -Path $Folder -ItemType directory
}
$Ent=Get-ChildItem "C:\Test" -Recurse -Force -include *.$YY$, *.tmp, *.temp, *.DS_Store, *.part, ~$*, Thumbs.db
foreach($i in $Ent){
if($i.mode -match "h"){
$Att[$i]=$i.Attributes
$Att[$i]=$Att[$i] | where{$_ -ne "Hide"} #questo non va
$i.Attributes = $Att[$i]
}
$Move=$Move+$i.fullname
Move-Item $i.fullname -Destination $Folder
}
$Move= $Move | sort{Split-Path( $_ ) -leaf}
$drives = foreach ($path in $Move) {
$prophash = @{
Nome= split-path $path -leaf
Percorso = $path
}
#create a new object from the property hash
New-Object PSObject -Property $prophash
}
#embed the style in the html header
$head = @'
<Title>Deleting Temp Report</Title>
<style>
body
{
background-color:#FFFFFF;
font-family:Verdana;
font-size:12pt;
}
td, th
{
border:1px solid blue;
border-collapse:collapse;
}
th
{
color:white;
background-color:green;
}
table, tr, td, th { padding: 5px; margin: 0px }
table { margin-left:50px; }
</style>
'@
#create an xml document from the HTML fragment
[xml]$html = $drives | ConvertTo-Html -fragment
#check each row, skipping the TH header row
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$class = $html.CreateAttribute("class")
}
#create the final report from the innerxml which should be html code
$body = @"
<H1>Deleting Temp Report for $Folder</H1>
$($html.innerxml)
"@
#put it all together
$Name = "Deleting Temp " + $Today
ConvertTo-HTML -head $head -PostContent "<br><i>$(Get-date)</i>" -body $body |
Out-File "C:\Log\$Name.html" -Encoding ascii
Invoke-Item "C:\Log\$Name.html""
qualche idea per scriverlo meglio?
Grazie
A