24. november 2011

Delete cookies

Hello,
Just had a user calling me telling me that on a specific site where the user needs to log in and specify a location to where his documents are, it shows an invalid path to the old fileserver. 
Ruling out any GPO, i turned to cookies.  Since we never delete any cookies for the users, this one have had thousands og cookies!
I want to find cookies where this site have saved som informations and i just need the job done...

declaring the path to cookies (which is on a fileserver)
$path=\\Fileserver\svprofil$\System\SVJVI\Citrix\H5\cookies

Now get all the cookies
$cookies=Get-ChildItem $path

now find the cookies that contains the specific site$matchCookies=$cookies | Select-String -Pattern "<specific site>"


$matchCookies | gm reveals that

   TypeName: Microsoft.PowerShell.Commands.MatchInfo
Name         MemberType Definition
----         ---------- ----------
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
RelativePath Method     string RelativePath(string directory)
ToString     Method     string ToString(), string ToString(string directory)
Context      Property   Microsoft.PowerShell.Commands.MatchInfoContext Context {get;set;}
Filename     Property   System.String Filename {get;}
IgnoreCase   Property   System.Boolean IgnoreCase {get;set;}
Line         Property   System.String Line {get;set;}
LineNumber   Property   System.Int32 LineNumber {get;set;}
Matches      Property   System.Text.RegularExpressions.Match[] Matches {get;set;}
Path         Property   System.String Path {get;set;}
Pattern      Property   System.String Pattern {get;set;}


in order to remove a file we need the entire path.  We dont have fullname in out members, but we do have filename.  I use the path from before and melt it with the attribute filename.

$cookies | Select-String -Pattern "danskebank" | foreach{"$path\"+$_.filename}
file://fileserver/profileShare$/System/Username/Citrix/H/cookies/BJ9NTMU2.txt
file://fileserver/svprofil$/System/SVJVI/Citrix/H/cookies/MFBOIQR5.txt
file://fileserver/svprofil$/System/SVJVI/Citrix/H/cookies/8VN8Y5A5.txt


now its just to implement remove-item:

$cookies | Select-String -Pattern "danskebank" | foreach{remove-item ("$path\"+$_.filename)}

jobs done :)

Ingen kommentarer:

Send en kommentar