Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Delete Old Profiles without prompt

$
0
0

Good Afternoon

I currently have this Powershell script

$Filedays = "-10" $servers = "SERVER1"

$docpath = "\\$server\C$\Documents and settings" foreach($server in $servers){ $users = Get-ChildItem -exclude 'all users' $docpath } $users | where-object { $_.LastWriteTime -lt (Get-Date).AddDays($FileDays)} | Remove-Item


I aim to run this and that would delete the users profile folder from docs and settings area of the expected server ovr xx days

However when running this i am informed that the folder contains child items and to use -recurse for this to work

When i use the -recurse it takes an age to remove the users folder from the doc and settings area, i want to simply say delete and that's it

Is there a quicker way to delete a folder without it having to manually trawl through and remove each child within? i simply want to permanent delete the folder returned

Any Advice would be appreciated

Barrie



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>