|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
[SOLVED]Server Storage Management
Buongiorno!
Oggi sto lavorando con una VM con Windows server 2008 R2 avente come ruolo File Services, in particolare File Server e File Server Resource Manager. Ho impostato una cartella, su cui ho il controllo completo, chiamata Test sulla quale vorrei effettuare un test appunto per capire come posso fare quanto segue. ![]() Premetto che ciò che voglio fare va schedulato in modo che venga applicato ogni giorno alle 13. Voglio eliminare tutti i file Temporanei quali Thumbs.db o i file di "Backup" di office, per chiarirci quelli che hanno il $ e che vengono creati quando il programma crasha, o simili. Per lo specifico file Thumbs.db ho già introdotto una regola ad obiectum, ma per gli altri file no... Inoltre esiste un modo per eliminare le cartelle vuote in automatico? Non sono molto pratico in merito; avreste qualche suggerimento? ![]() Grazie A Ultima modifica di Albiz849 : 27-11-2013 alle 09:15. Motivo: [SOLVED] |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2001
Città: Kendermore
Messaggi: 6686
|
Io lo farei con un semplice script bash installando cygwin sul server.
Ti basta usare il comando find ed rm. Per i file puoi usare Codice:
find <PATH> -type f -name '\$*' -o -name 'Thumbs.db' | xargs rm -f Codice:
find <PATH> -type d | xargs rmdir --ignore-fail-on-non-empty
__________________
https://tasslehoff.burrfoot.it | Cloud? Enough is enough! | SPID… grazie ma no grazie "Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say." |
|
|
|
|
|
#3 | |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Quote:
Quanto alla directory... ehm... di script non ne so niente :-( hai per caso una guida? TNX :-) |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Sep 2008
Messaggi: 3583
|
Visto che è su Windows perchè installare cygwin e non usare PowerShell?
http://technet.microsoft.com/en-us/l.../hh849852.aspx |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Nov 2001
Città: Kendermore
Messaggi: 6686
|
Quote:
Non discuto della potenza di Powershell, però il fatto di essere limitato a Windows imho è sufficiente per scartarlo a priori.
__________________
https://tasslehoff.burrfoot.it | Cloud? Enough is enough! | SPID… grazie ma no grazie "Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say." |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Sep 2008
Messaggi: 3583
|
Dipende cosa gestisci.. Se sono solo server Windows non ha senso usare altro, visto che l'editor con debugger è già compreso ed è un software nativo
Inviato dal mio Nexus 5 con Tapatalk |
|
|
|
|
|
#7 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Buongiorno!
Vi ringrazio per le risposte, vi informo inoltre che sto lavorando solo su server Windows, o per lo meno l'unico file service è su vm Windows. Spero di poter consultare a breve il link fornito ma oggi il sito Microsoft TechNet sembra non funzionare, spero che la cosa si risolva in breve tempo. Vorrei, se possibile, sapere se esiste un metodo per generare un report sui file duplicati; io ho già provato con il "tool" presente nello Storage Reports Management ma identifica solo file con lo stesso nome, a me servirebbe un controllo bit a bit. Preciso che attualmente, se un file si chiama a.ext e ne rinomino una copia in A.ext non viene visto come duplicato; a me farebbe piacere poter rinominare la copia di a.ext in b.ext e farli identificare come doppioni, duplicati insomma.... Grazie A |
|
|
|
|
|
#8 | |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Quote:
Codice:
$Dir="C:\Test"
foreach( $In in(Get-ChildItem $Dir -Recurse){
if(!(Get-ChildItem -Path $In.FullName)){
echo $In.FullName;
Remove-Item $In.FullName
}
}
Codice:
Get-ExecutionPolicy=Restricted grazie A |
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Sep 2008
Messaggi: 3583
|
Con il task scheduler metti un'action con Program/Script "Powershell" e argument il percorso del file ps1
|
|
|
|
|
|
#10 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Grazie!!!
A |
|
|
|
|
|
#11 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
[SOLVED] maybe
CVDecco il classico errore di distrazione... Alcune cartelle sono organizzate con dei numeri come prefisso es 00 - Organizzazione... queste cartelle, sebbene possano essere vuote NON DEVONO ESSERE ELIMINATE. Cosa che puntualmente non avviene... pensavo a un ciclo Codice:
if(Folder start with(lista)){skip}
Grazie A Codice:
$Dir="C:\Test"
$Et1="0"
$Et2="9"
foreach( $In in(Get-ChildItem $Dir -Recurse)){ #per ogni cartella in $Dir
if(!(Get-ChildItem -Path $In.FullName)){ #se non hai figli
$Sav=Split-Path( $In ) -leaf; #prendi il nome della cartella
if(!($Sav.StartsWith($Et1)) -and (!($Sav.StartsWith($Et2)))){ #se non fa parte delle eccezioni
echo $In.FullName; #stampa
#Remove-Item $In.FullName
}
}
}
Ultima modifica di Albiz849 : 19-11-2013 alle 14:10. |
|
|
|
|
|
#12 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Eureka!!!
Per la serie... sono un rompi*****...
Sto tentando di creare un report per i file duplicati, dato che non ho intenzione di affidarmi a software o regole di default... Quindi ho preso uno script per i file duplicati e un generatore di file html e sto tentando di metterli assieme... Codice:
function Get-Double {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[System.String]
[Alias('PSPath')]
$Path
)
if ((Test-Path -Path $Path) -eq $false) {
throw New-Object System.IO.FileNotFoundException($Path)
}
try {
$item = Get-Item -Path $Path -Force -ErrorAction Stop
}
catch {
throw
}
if ($item -isnot [System.IO.FileInfo]) {
throw New-Object System.ArgumentException('Specified path must refer to a File object.','Path')
}
try {
$bytes = [System.IO.File]::ReadAllBytes($item.FullName)
} catch {
throw
}
$md5Hash = [System.Security.Cryptography.MD5]::Create()
$hashBytes = $md5Hash.ComputeHash($bytes)
$sb = New-Object System.Text.StringBuilder
foreach ($byte in $hashBytes) {
$sb.Append($byte.ToString("x2")) | Out-Null
}
Write-Output $sb.ToString()
}
$files = @{}
$folder = 'C:\Test\' # Il percorso su cui lavorare
Get-ChildItem -Path $folder -Force -Recurse |
Where-Object { $_ -is [System.IO.FileInfo] } |
ForEach-Object {
try {
$hash = $_ | Get-Double
} catch {
Write-Error -ErrorRecord $_
return
}
if ($files.ContainsKey($hash) -eq $false) {
$files[$hash] = New-Object 'System.Collections.Generic.List[System.String]'
} else {
# I'm just identifying duplicates by adding all their names to a list.
# Keep in mind that if two files have identical hashes, they could have
# different contents; it's possible for two different inputs to produce the same
# hash code.
}
$files[$hash].Add($_.FullName)
}
$data=@()
foreach ($entry in $files.GetEnumerator()) {
if ($entry.Value.Count -gt 1) {
$data=$data+$entry.Value
}
}
#$data= $data | sort{Split-Path( $data ) -leaf} possibilità di ordinare per nome(Verificare)
$drives = foreach ($path in $data) {
$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>Double 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>Double Report for $Folder</H1>
$($html.innerxml)
"@
#put it all together
ConvertTo-HTML -head $head -PostContent "<br><i>$(Get-date)</i>" -body $body |
Out-File "C:\Test\Double.html" -Encoding ascii
Invoke-Item "C:\Test\Double.html"
Grazie di tutto!!!! Adesso provo a farlo girare sul server... :-) A Ultima modifica di Albiz849 : 21-11-2013 alle 13:04. Motivo: [SOLVED] |
|
|
|
|
|
#13 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
Quando il lavoro sembra finito emergono i problemi
Ciao!
Vorrei modificare gli attributi di alcuni file. se il file è nascosto va tolto il flag e renderlo dunque visibile Se vi viene in mente qualcosa... Grazie!! A Ultima modifica di Albiz849 : 25-11-2013 alle 10:31. |
|
|
|
|
|
#14 |
|
Junior Member
Iscritto dal: Oct 2013
Messaggi: 26
|
[SOLVED]Si potrebbe fare meglio...
Codice:
$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"
Grazie!! A Ultima modifica di Albiz849 : 27-11-2013 alle 09:16. Motivo: [SOLVED] |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:58.













CVD








