Question about: Use PowerShell to Toggle the Archive Bit on Files

Hi Scripting Guys,

thanks for you favorite scripts. but one question: the script abovementioned running. But I have to enter a -value for each file. If the script is not written so that each file checked for the archive and then changed? Apparently it does not work right with me.
Here is the script again and also a screenshot. Over a short help I would be delighted.
Stephan

$path = "C:\fso"

$files = Get-ChildItem -Path $path -Recurse

$attribute = [io.fileattributes]::archive

 

Foreach($file in $files)

{

 If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute)

  {

   "$file.fullname has the $attribute bit set, removing the bit."

   Set-ItemProperty -Path $file.fullname -Name attributes

   -value ((Get-ItemProperty $file.fullname).attributes -BXOR $attribute)
     

   "New value of $file.Fullname attributes"

   (Get-ItemProperty -Path $file.fullname).attributes

  }

 ELSE

  {

    Write-host -ForegroundColor blue

    "$file.fullname does not have the $attribute bit set, setting the bit."

    Set-ItemProperty -Path $file.fullname -Name attributes

      -value ((Get-ItemProperty $file.fullname).attributes -BXOR $attribute)
    

    "New value of $file.Fullname attributes"

   (Get-ItemProperty -Path $file.fullname).attributes

    }
} #end Foreach

April 21st, 2015 2:08pm

Any particular reason you are not using the attrib command?

Type attrib /? for instructions.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 3:20pm

Hi Bill,

thanks for answering. Instead of what value should I put it? Its maybe a simple question, but I use PS for only a few days.

April 21st, 2015 3:33pm

I don't understand your question. What value of what should you put where?

Try to explain in simple language what you want to do.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 3:38pm

The attrib command isn't a PowerShell cmdlet:

http://ss64.com/nt/attrib.html

If you're asking which line of your script this should replace, the answer is 'the entire thing'.

April 21st, 2015 3:41pm

OK, I will try it.
I want to check all the files in a directory if an archive bit is set or not.
If none is set, then I want to put an archive.

After the files are to be moved as backup files.

Thank you
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 3:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics