Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Thumbs up [SOLVED][POWERSHELL] Remove Hide Attribute

    Hi guys!
    I'm a newbie about powershell, I just started programming last week ...
    I have a folder with some files, I do not know how many they are, what is their extension or attributes.
    I want to make sure that, if a file has among the attributes the hidden property (so it can have even more properties ), only hidden property is removed.
    How can i do it ?
    This is what i've done:
    Code:
    $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"
    Any ideas ?
    Thanks
    A
    Last edited by Albiz; 2013-11-27 at 04:13. Reason: [solved]

  2. #2
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Los Angeles, CA
    Posts
    828
    Thanks
    4
    Thanked 38 Times in 34 Posts
    You marked this post as solved. I would be nice if you shared the solution (in a new post, don't just update the code in the existing post). That way others will also know the solution. (If you haven't solved it, let me know, I'll provide some hints.)

  3. #3
    New Lounger
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Here the code:
    Code:
    $Move=@()
    $Today = Get-Date -Format "dd-MMM"
    $Folder= "C:\Estinto\$Today\Temporary"
    $Search= "C:\Test"
    #se gli elementi da ricercare dovessero aumentare si potrebbe creare un array che li contenga
    
    if(!(Test-Path $Folder)){
        New-Item -Path $Folder -ItemType directory
    }
    
    $Ent=Get-ChildItem $Search -Recurse -Force -include *.$$$, *.$YY$, *.tmp, *.temp, *.DS_Store, *.part, ~$*, Thumbs.db, *.wbk
    foreach($i in $Ent){
        if($i.mode -match "h"){
            $split=$i.Attributes -split(', ')
            $join=($split | where{$_ -ne "Hidden"}) -join(', ')
            if($join -eq ""){
                $i.Attributes = [System.IO.FileAttributes]::Normal
            }
            else{
                $i.Attributes = $join
            }
        }
        $Move=$Move+$i.fullname
        $Divide=$i.directory.fullname -split('')
        $Impera=""
        foreach($count in $divide){
            if($count -match ':'){
                $count="$" 
            }
            $Impera += $count
        }
        $Dest=$Folder,$impera -join('\')
            if(!(Test-Path $Dest)){
                New-Item -Path $Dest -ItemType directory
            }
            
        Move-Item $i.fullname -Destination $Dest 
    }
    
    
    $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 $Search</H1>
    $($html.innerxml)
    "@
    
    #put it all together
    $Log = "Deleting Temp " + $Today
    
    ConvertTo-HTML -head $head  -PostContent "<br><i>$(Get-date)</i>  Files will be moved to $Folder" -body $body | 
    Out-File "C:\Log\$Log.html" -Encoding ascii
    
    Invoke-Item "C:\Log\$Log.html"
    Have a good day!
    A

  4. #4
    New Lounger
    Join Date
    Sep 2013
    Posts
    22
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hi guys!
    Can you tell me why this function doesn't work?
    Code:
    function Hide_And_Temp{
        Dir $Search -Recurse -Force -Include *.$$$, *.$YY$, *.tmp, *.temp, *.DS_Store, *.part, ~$*, Thumbs.db, *.wbk |
        ForEach-Object{
            if($_.mode -match "h"){
                $_.mode -replace "h","-"
            }
            $script:Move+=$_.fullname
            $From=$_.Directory -replace ":","$"
        }
        return $From
    }
    $_.mode is still the same...
    why???
    Thanks
    A

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •