PowerShell format output -


I am trying to write a script that removes all the folders that are more than 60 days old, Together, create a logfile where folders have been removed in the directory.

What I have now:

  go-childItem- directory - path "\\ share \ dir1 \ dir2" | Where-Object {$ _ Last Light-Late (Get-Date) Adwords (-10)} | Remove-item-force-rectifier | Out-File Auto_Clean.log -Append -WhatIf  

The output resides in:

  What if : Performing "Output" in the operation "file" on "C: \ user \ bgijbels \ downloads \ Auto_Clean.log".  

When I click the Out-File It works fine, so it seems that part of the out-file is trying to write the name of every file in the folder in the log, whereas I should only have the name of the folder. It seems that this is the reason that it looks so long, if everything goes past of logfile, any thoughts? Thanks for your help.

You are receiving a list of all the files because -Recurse switches the contents of the switch folders so that it is removed before removing the root folder Try it:

Go-Child ITEM - Directory - Path "\\ share \ dir1 \ dir2" | Where-OB Ekt {$ _ Last Laittaim -elti (gate-to date). Addition (-60)} | % {$ Folder = $ _; Remove- items $ folder.FullName -Force -Recurse | Out-null $ folder.FullName} | Outroot Auto_Clean.log -Append -WhatIf

The directory object is placed in the form of $ folder var and after deletion you can effectively complete its path Resonate with Obviously, after being happy with the result, move -WhatIf to the end.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -