John Delise
asked on
Can you use PowerShell to selectively delete certain Internet Explorer Temporary Internet files in the cache
We want to write a script that based on a txt pattern found in the file properties, will delete a file with that pattern in it's name or Internet Address property.
The iNetCache files display when you go into the general tab of IE options and select view files. the columns have properties of the files, Name, Internet Address, Type etc. But they are not really in that folder, this is a user friendly display, you can right click on any of the files and look at the properties page to see the true location.
We were able get the get-childitem powerShell command to to get the file objects for all files under c:\users\<Username>\Micros oft
(Carefull line is wrapping) Using the commands below, but the properties returned do not include the "Internet Addresss" property.
#Get the Folder name for the users InetCache
$_userInetCacheFolder = "$($ENV:UserProfile)\AppDa ta\Local\M icrosoft\W indows\INe tCache"
$_UserInetLeafObjects = Get-ChildItem -Path $_userInetCacheFolder -force -recurse
How do we retrieve the "internet address" property as part of the file object information returned.
If we had it we would use a foreach loop to do a match comparison to the a text string, say "dmus", if the "dmus" string was in the internet address property value we would delete that file and any other file of Type "HTML Document" or "COOKIE file"
Unless I can match on a pattern on one or more of those properties, it does not seem doable.
The iNetCache files display when you go into the general tab of IE options and select view files. the columns have properties of the files, Name, Internet Address, Type etc. But they are not really in that folder, this is a user friendly display, you can right click on any of the files and look at the properties page to see the true location.
We were able get the get-childitem powerShell command to to get the file objects for all files under c:\users\<Username>\Micros
(Carefull line is wrapping) Using the commands below, but the properties returned do not include the "Internet Addresss" property.
#Get the Folder name for the users InetCache
$_userInetCacheFolder = "$($ENV:UserProfile)\AppDa
$_UserInetLeafObjects = Get-ChildItem -Path $_userInetCacheFolder -force -recurse
How do we retrieve the "internet address" property as part of the file object information returned.
If we had it we would use a foreach loop to do a match comparison to the a text string, say "dmus", if the "dmus" string was in the internet address property value we would delete that file and any other file of Type "HTML Document" or "COOKIE file"
Unless I can match on a pattern on one or more of those properties, it does not seem doable.
If you look at desktop.ini, the directory list of that folder is backed by a COM object. If the COM object can be accessed you can have everything. Looking...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris,
This provides the information that I need to continue creating the solution. Not being a C# coder I was stymied since it could not be done in native Powershell without your solution. the function you provided returns both the type, path and URL content which I need to query against to choose which ones to delete.
The hash returned
lpszSourceURLname which has the URL information I need to match on
lpszLocalFilename which will be populated only if there is a local file in the cache and it has it's literpath
So the logic is straight forward even for a mid-level powershell coder.
If the URL name has the pattern(s) I am looking for, delete the file using the fully qualified path provided in the lpszLocalFileName.
You have busted through my road block. Great work!
This provides the information that I need to continue creating the solution. Not being a C# coder I was stymied since it could not be done in native Powershell without your solution. the function you provided returns both the type, path and URL content which I need to query against to choose which ones to delete.
The hash returned
lpszSourceURLname which has the URL information I need to match on
lpszLocalFilename which will be populated only if there is a local file in the cache and it has it's literpath
So the logic is straight forward even for a mid-level powershell coder.
If the URL name has the pattern(s) I am looking for, delete the file using the fully qualified path provided in the lpszLocalFileName.
You have busted through my road block. Great work!
Glad it helped :)
Wrong closing comment?
ASKER
This is the first time I have posted a question, I seem to have not closed this properly. If not please advise how to.
in any case Chris Dents post did solve the problem for me and should be considered the Best Solution.
in any case Chris Dents post did solve the problem for me and should be considered the Best Solution.
ASKER
Chris Dents post solved the problem for me.