Network Folder delete

Our AV solution makes temp files on all our servers in the Windows directory. 
Im looking for a script I can run locally that reads from a serverlist.txt -> 
goes out and deletes all folders and their contenets in the following 
directory:   C:\WINDOWS\SoftwareDistribution\ScanFile - except for today.

I've searched high and low and seen pieces, such as reading over the 
network, searching for files based on date, deleting files (not folders), but 
nothing quite like my request. Any scripting help would of course greatly be 
appreciated! Thanks!
0
Utf
1/13/2010 10:00:01 PM
windows.powershell 690 articles. 0 followers. Follow

10 Replies
4449 Views

Similar Articles

[PageSpeed] 51

Let me add the following process below - perhaps someone can translate it to 
powershell? Thanks

$a = Get-Content C:\Scripts\serverlist.txt
foreach $a
Net Use T$ \\a$\c$\WINDOWS\SoftwareDistribution\ScanFile
dir | sort-object LastWriteTime
last write directory = Z$
delete eveerything but Z$
net use t$ /delete

(contine looping through servers until complete)
0
Utf
1/14/2010 4:25:01 PM
Nothing like replying to your own thread - ok Im closer - I think -- anyone?
-instead of delete - lets just try try to count the files in the remote 
share ? anyone?

(this fails)

$server = "c:\scripts\serverlist2.txt" 
foreach {set-location -path \\$server\system32\ | (dir).count}
0
Utf
1/14/2010 10:01:01 PM
I think this will get the job done.  This is assuming that you are only 
wanting to delete folders in the ScanFile folder.  

"Ian_1" wrote:

> Let me add the following process below - perhaps someone can translate it to 
> powershell? Thanks
> 
> $a = Get-Content C:\Scripts\serverlist.txt
> foreach $a
> Net Use T$ \\a$\c$\WINDOWS\SoftwareDistribution\ScanFile
> dir | sort-object LastWriteTime
> last write directory = Z$
> delete eveerything but Z$
> net use t$ /delete
> 
> (contine looping through servers until complete)

$servers = Get-Content c:\scripts\serverlist.txt

foreach($server in $servers)
{
	$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | where 
{$_.psiscontainer -eq $true}
	foreach ($folder in $folders)
	{
		$lastwrite = $folder.lastwritetime.date
		$today = (Get-Date).date
		
		If ($lastwrite -lt $today)
		{
			#$folder | Remove-Item
			$folder
		}
	}
}
0
Utf
1/15/2010 1:00:01 AM

"mayben" wrote:

> I think this will get the job done.  This is assuming that you are only 
> wanting to delete folders in the ScanFile folder.  
> 
> "Ian_1" wrote:
> 
> > Let me add the following process below - perhaps someone can translate it to 
> > powershell? Thanks
> > 
> > $a = Get-Content C:\Scripts\serverlist.txt
> > foreach $a
> > Net Use T$ \\a$\c$\WINDOWS\SoftwareDistribution\ScanFile
> > dir | sort-object LastWriteTime
> > last write directory = Z$
> > delete eveerything but Z$
> > net use t$ /delete
> > 
> > (contine looping through servers until complete)
> 
> $servers = Get-Content c:\scripts\serverlist.txt
> 
> foreach($server in $servers)
> {
> 	$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | where 
> {$_.psiscontainer -eq $true}
> 	foreach ($folder in $folders)
> 	{
> 		$lastwrite = $folder.lastwritetime.date
> 		$today = (Get-Date).date
> 		
> 		If ($lastwrite -lt $today)
> 		{
> 			#$folder | Remove-Item
> 			$folder
> 		}
> 	}
> }

Whoops.  To get it to delete just uncommend #$folder | Remove-Item
0
Utf
1/15/2010 1:10:01 AM
I think your close, Im getting the following error though:

PS C:\scripts> C:\scripts\del_files.ps1

cmdlet where at command pipeline position 2
Supply values for the following parameters:
FilterScript:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
to type "System.Management.Automation.Scri
ptBlock". Error: "Invalid cast from 'System.String' to 
'System.Management.Automation.ScriptBlock'."
At C:\scripts\del_files.ps1:4 char:77
+ {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
where  <<<<
$_.psiscontainer -eq $true
Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\scripts\del_files.ps1:10 char:23
+ {$folder | Remove-Item <<<<

cmdlet where at command pipeline position 2
Supply values for the following parameters:
FilterScript:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
to type "System.Management.Automation.Scri
ptBlock". Error: "Invalid cast from 'System.String' to 
'System.Management.Automation.ScriptBlock'."
At C:\scripts\del_files.ps1:4 char:77
+ {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
where  <<<<
$_.psiscontainer -eq $true
Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\scripts\del_files.ps1:10 char:23
+ {$folder | Remove-Item <<<<

cmdlet where at command pipeline position 2
Supply values for the following parameters:
FilterScript:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
to type "System.Management.Automation.Scri
ptBlock". Error: "Invalid cast from 'System.String' to 
'System.Management.Automation.ScriptBlock'."
At C:\scripts\del_files.ps1:4 char:77
+ {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
where  <<<<
$_.psiscontainer -eq $true
Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\scripts\del_files.ps1:10 char:23
+ {$folder | Remove-Item <<<<
0
Utf
1/15/2010 2:41:01 AM
Karl the script works great but just for counting. So if I wanted to change 
it to list the contaning directories, or sort and display the newest only, or 
best yet, delete everything- the commands at the end, I must be not using the 
correct format and I have replaced .count with everything from .dir alias, 
dir | where { $_.MshIsContainer }, dir | sort-object LastWriteTime,  del *, 
etc.  Nothing seems to work for those options. Am I using the incorrect 
process for this? Thanks
0
Utf
1/15/2010 3:27:01 AM
That's odd because this script as it is works fine in the test I'm doing.

"Ian_1" wrote:

> I think your close, Im getting the following error though:
> 
> PS C:\scripts> C:\scripts\del_files.ps1
> 
> cmdlet where at command pipeline position 2
> Supply values for the following parameters:
> FilterScript:
> Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
> to type "System.Management.Automation.Scri
> ptBlock". Error: "Invalid cast from 'System.String' to 
> 'System.Management.Automation.ScriptBlock'."
> At C:\scripts\del_files.ps1:4 char:77
> + {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
> where  <<<<
> $_.psiscontainer -eq $true
> Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
> At C:\scripts\del_files.ps1:10 char:23
> + {$folder | Remove-Item <<<<
> 
> cmdlet where at command pipeline position 2
> Supply values for the following parameters:
> FilterScript:
> Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
> to type "System.Management.Automation.Scri
> ptBlock". Error: "Invalid cast from 'System.String' to 
> 'System.Management.Automation.ScriptBlock'."
> At C:\scripts\del_files.ps1:4 char:77
> + {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
> where  <<<<
> $_.psiscontainer -eq $true
> Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
> At C:\scripts\del_files.ps1:10 char:23
> + {$folder | Remove-Item <<<<
> 
> cmdlet where at command pipeline position 2
> Supply values for the following parameters:
> FilterScript:
> Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "" 
> to type "System.Management.Automation.Scri
> ptBlock". Error: "Invalid cast from 'System.String' to 
> 'System.Management.Automation.ScriptBlock'."
> At C:\scripts\del_files.ps1:4 char:77
> + {$folders = gci "\\$server\c$\windows\softwaredistribution\scanfile" | 
> where  <<<<
> $_.psiscontainer -eq $true
> Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
> At C:\scripts\del_files.ps1:10 char:23
> + {$folder | Remove-Item <<<<
0
Utf
1/15/2010 1:55:04 PM
Is your server text file CSV or some other format? the script is stopping 
like its prompting for something. I press enter, or even try a server name 
and it errors out.
0
Utf
1/15/2010 3:10:01 PM
This script stays local to the location where I run it "C:\scrips" - it 
doesn't go to the remote server C$ location.

filter Files {
if (!$_.psIsContainer) 
{
	$_
}

Get-Content "c:\scripts\serverlist2.txt" | foreach {$FilesToDelete = 
@(Get-ChildItem 
"\\$_\c$\Windows\SoftwareDistribution\ScanFile\*" |Files |Sort-Object 
LastWriteTime 
-Descending)}

$FilesToDelete[1..($FilesToDelete.count -1)] |Remove-Item -WhatIf

}

---------------------------------------------------------
0
Utf
1/18/2010 3:43:01 PM
I am having a simlar issue:
I took 
this<http://www.networknet.nl/apps/wp/published/powershell-delete-files-older-than-x-days> and tweaked it.

$Now = Get-Date
$Days = “30”
$TargetFolder = “C:\Test”
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -recurse | Where {$_.LastWriteTime -le 
“$LastWrite”} 

foreach ($File in $Files)
{write-host “Deleting File $File.FullName” -foregroundcolor “Red” ; 
Remove-Item $File.FullName -recurse -force } 

Anyhow this works great if there are files it can delete.  If there are no 
files it gives
"
PS C:\Utilities\PS\Delete.old.files> 
C:\Utilities\PS\Delete.old.files\DeleteFiles30PlusDays.ps1
Deleting File .FullName
Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\Utilities\PS\Delete.old.files\DeleteFiles30PlusDays.ps1:8 char:80
+ {write-host “Deleting File $File.FullName” -foregroundcolor “Red” ; 
Remove-Item <<<<  $File.FullName -recurse -force } 
    + CategoryInfo          : InvalidData: (:) [Remove-Item], 
ParameterBindingValidationException
    + FullyQualifiedErrorId : 
ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand
 "

I think the issue is that is trying to delete null.  (No logic to detect 
empty directory.)
0
Utf
3/25/2010 5:03:02 PM
Reply:

Similar Artilces:

Public Folders "Owners not able to create sub-folders"
Using Exchange 2003 I have created Top level public folders for users that have requested them. I have granted a specific individual Owner - Client permissions. but when they try to create sub-folders they get the following error message "Unable to create the folder. you do not have sufficient permission to perform this operation on this object. See the folder contact or you system administrator." Any help on this would be much appreciated. Regards. David In the Exchange System Manager, Expand Folders > Public folders, right click and select properties. There are explicit...

Sharepoint Calendar auto-delete?
Hello. I was going through some of my Calendars in SharePoint and I noticed that items in SharePoint Calendars going missing. Looking into my Site Recycle Bin, I noticed that they were being deleted by the System Account on the items' End Date (at 11:59 of that day). Can anyone else confirm that Calendar entries are being auto-deleted on their End Dates? Is this a "by design" feature in WSS or MOSS? Is there any way to disable it - in case someone wanted to keep their entries for whatever reason? ...

how to apply a view globally to all folders #2
lots of answers but none of them work.. here is the actual solution.. works like a charm.. http://techrepublic.com.com/5100-6270_11-5243615.html ...

Troubles with sharing over business network
I am trying to set up computers that are running on a small business network. We need to share folders that are on the desktop but when we set them up to be shared they are not recognized by the other computers. There are a few computers that are working but our newer computers are not. Nathan Niewohner wrote: > I am trying to set up computers that are running on a small business network. > We need to share folders that are on the desktop but when we set them up to > be shared they are not recognized by the other computers. There are a few > computers that are worki...

outlook personal folder
My personal folder is just over 2gb and I can't seem to delete anything in the folder to make some more space as the outlook software just freezes. Is there a way of deleting these folders without the software freezing For earlier versions of Outlook 2GB is the max check out http://www.slipstick.com/problems/repair2gbpst.htm for a tool that can be used to crop some date, unfortunately this will result in data loss "marilyn" <anonymous@discussions.microsoft.com> wrote in message news:067601c3fad8$6128ce50$a001280a@phx.gbl... > My personal folder is just over 2gb and...

deleted attachments
Several attachments from outside email addresses that my users know and promise are safe have been deleted. Where can I find these attachments? Also, where can I change the settings for what attachments are let through? ...

Deleting multiple items
Is there a way to delete multiple reports, catagories, payees at the same time? "shift arrow" and "control arrow" does not seem to work. Thanks mj No. "mj" <mj@discussions.microsoft.com> wrote in message news:3FFD5B0C-B899-4618-A4DB-1115ADCD9267@microsoft.com... > Is there a way to delete multiple reports, catagories, payees at the same > time? "shift arrow" and "control arrow" does not seem to work. Thanks > mj > Dick, that is not the answer that I was looking for. LOL mj "Dick Watson" wrote: > ...

Can you password protect a folder?
Can a folder be password protected so that you don't need to password protect every file that is in the folder? I suggest asking your network support to change the access to your folder, or create a new folder. Give them a list of users who should be able to view or edit files in that folder. "Shrimp913" wrote: > Can a folder be password protected so that you don't need to password protect > every file that is in the folder? ...

open folder
Whenever I start Outlook 2000, one of the sub-folders always opens up expanded, all the others are closed. The program starts with the inbox selected which is as I want it, but how do I get this particular sub-folder to start up closed? Outlook doesn't seem to remember the current setting when I close it. I cannot find anything under Tools. Thanks in advance, Geoff. ...

Outlook 2003 folders
Hi, I have moved from Outlook 2000 to 2003, but the 2000 was a french version, and the 2003 is english, and I would like to change the names of the inbox and so on to be in english instead of french but I can't find out how to do that except by recreating the whole thing from start, which would mean that I'd loose everything. -- Thank you in Advance Merci a l'Avance Martin Try starting Outlook once with the /ResetFolders switch. If you need help using Outlook command line switches, look here: http://support.microsoft.com/default.aspx?scid=kb;en-us;296192 -- Jocelyn Fio...

Getting my Library to match my Folder structure
This question has been asked before in various incantations, but I have to blow off some steam here. I WANT TO DELETE MY MUSIC LIBRARY THEN HAVE IT RESCAN MY MUSIC FOLDER (D:\MUSIC) PICKING UP JUST WHAT IS THERE AND REFLECTING THE DIRECTORY STRUCTURE WITHIN. The reason is that the "Library" keeps showing me some duplicate entries and a couple of "artist" folders not named the way I want. I assumed I could kill the library database, and have it rescan the folder. Unfortunately I haven't been able to get the old library deleted for good. Now, I have t...

Folder shaing across domains
I have 2 AD forests with full trust. Each has its own domain and exchange server. I'd like a user from domain1 to share a calendar with a user on domain2. I'm currently using the sync util to synchronize certain public folders and I could create matching mailboxes on both servers but legally these 2 domains have to mostly remain separate. I can't have the CEO of one company having a full synced mailbox on the exchange server for the other but they need to see his calendar only. Is this possible and how would one do it since one Exchange server can't see the other's i...

Outlook and Being Networked
I have a two PC running Outlook 2003. Both our networked together through our wireless network, both running XP Home Edition. I'm wanting to keep both .pst files current on each PC so that no matter what PC you currently use, you can access your files and such. I've looked and have read most of the links and articles on http://www.slipstick.com/outlook/sync.htm and have read many KB articles on Microsoft. Most of these programs cost and I've tried some over their trial period and didn't quite like how they operated or it just wasn't what I needed. So, how can one...

Delete amounts
Hi Is there anyway I can delete amount from each row using a formula? I have over 600 transactions from which I need to delete amount. thank you 2ND ST BISTRO POMONA, CA $23.38 7-ELEVEN 33242 ROSEMEAD, CA $5.15 7-ELEVEN 33242 ROSEMEAD, CA $7.00 99-CENTS-ONLY #0107 UPLAND, CA $4.23 99-CENTS-ONLY #0107 UPLAND, CA $6.00 Assume that you are having the below value in A1 cell A1 Cell 2ND ST BISTRO POMONA, CA $23.38 Put this formula in B1 cell =TRIM(LEFT(A1,SEARCH("$",A1)-1)) Change the cell reference to your desired cell, if required. Remember to Click Yes, if t...

Public Folders
We recently upgraded to Entourage 11.2.4. In addition to each user having their own Exchange account setup for email, our company also has a Public Folder account called "Submit" which is setup to receive customer messages containing attachments. A handful of employees have access to this Public Folder. Since installing the Entourage upgrade we have noticed that we now receive the "Get Entire Message" error on any emails containing attachments that come into the "Submit" account. We have verified the Options for the user's account are set to Receive Complete ...

Confirm Delete Message Disable
When I delete a sheet which has data I get the standared confirmation dialog allowing me to delete or cancel. This is a problem because I would like to do this from a remote VB pgrogam. Is there a way to disable this dialog ? Try, Application.DisplayAlerts = False 'Your code to do your thing Application.DisplayAlerts = True Regards, Alan "RiosPapa" <RiosPapa@discussions.microsoft.com> wrote in message news:35D5C93D-5EEA-4EDD-9463-E2E845E01933@microsoft.com... > When I delete a sheet which has data I get the standared confirmation > dialog > allowing me to d...

OLK8 folder, where is it, how do I open it?
Outlook default saves attachments to OLK8 folder, whatever that is. I can't find it either by manually searching with Win Explorer or using the lame search functions of WindowsXP. OLK8 has a zip file of mine and it won't give it up. How do I open the folder? Thanks, Robert ...

File opening problem over network
I have what seems to be a strange excel file opening issue that I can't pinpoint and I would greatly appreciate any ideas to try for this problem. We have a network computer running windows 98 SE. On this computer there are many .xls files stored for users to access. Often when opening the files users get an error that reads: Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk pace. -To make more memory available, close workbooks or programs you no longer need. -To free disk space, delete files you no longer need from the disk yo...

Trying to move messages to folders
When I try to move certain email messages to other folders (manually), suddenly I get this message: "The messaging interface has returned an unknown error. If the problem persists, restart Outlook." Even with the restarts, I still get the error messages. I looked up the error message in the database, but it seems to be listed only in cases where you're forwarding mail, not moving it. I also checked for updates to Outook 2002, but the scan said I was up-to-date. This all happened, by the way, after I installed Service Pack 2. Can anyone help? Thanks so much! ...

networking
My question is, we want to setup a calander for everybodies use at our office. Do we need a server or can we run off of our office network? Bottom line question is, can 6 to 8 people use Outlook at the same time without a dedicated server? If so how? Thanks for the help! Ted. simply setup a calendar on a single users outlook installation, then give all other users permission to view and edit that calendar. you may also have to look at some kind of sharing for the drive the outlook is on. It's just like giving your secretary access to your inbox HTH Pete >-----Original ...

urgent owa ssl public folder access issue
hello all, on win2k3 exchange 2003 we run owa, everything was ok untill we implemented ssl security. we now cannot access the public foldes by owa. owa is the only client we use, so no outlook thick clients. ssl has been set on the following virtual folders: exchange, public and exchweb. at first there was an event log: type: error id 36884 source Schannel also when trying to access public folders through exchange system manager there was a popup with the following error: the ssl certificate server name is incorrect id no: c103b404 exchange system manager after uninstalling certificate ser...

Fading letters on Outlook Folders
Has anyone seen this? The last letters on a folder name start to fade away. If I remane it, the letters of the folder are bold again. Bruce ...

Delete a user from a team.
Hi, Can someone tell me how to delete a user from a team? The team must stay as it is and the user must go to another team. I don't want the user to view the account of my team. Looking forward to your response. Thanks, Oumoulid Go to Settings / Business Unit Settings / Teams. Double-click on the Team name from the grid displaying all teams. Click on the Members tab. Select the line containing the user you wish to remove from the team. Select Actions / Remove Member. Teams are very helpful, good luck, Dave ------------------------------------------------- David L. Carr, President...

Public folders #31
we have mail coming into public folders in exchange 2003 - when people reply to these mails, understandably the from address would be from the user who is replying - we want to have the from address as the public folder address. you can change this when you send the mail in the options menu but exchangfe doesn't like it and throws the following message back: Your message did not reach some or all of the intended recipients. Subject: RE: testing Sent: 01/02/2005 09:24 The following recipient(s) could not be reached: Peter Pickthall on 01/02/2005 09:24 You do not have permission to...

moniter network usage on the network
I want to moniter the bandwidth/internet usage of all of the devices on our network. Some are wired and some are wireless through a wifi connection. How would I get started doing something like this? > I want to moniter the bandwidth/internet usage of all of the devices on > our network. Some are wired and some are wireless through a wifi > connection. How would I get started doing something like this? Might be outside the C# topic, but IF your traffic (even internal) is passing through a firewall, or it's passing through a switch that supports mirroring, you...