Junior Sofe
asked on
PowerShell Script to Search for PST files
I had this question after viewing Powershell script to find files on network computers..
I am trying to create a script on how to search for pst files in the hard drive. How can I achieve this? Any help on the script would be appreciated.
Thanks
I am trying to create a script on how to search for pst files in the hard drive. How can I achieve this? Any help on the script would be appreciated.
Thanks
Is it just for one user only or all users in all AD domain ?
ASKER
@ ITSystemEngineer...
For a start, its just only for one user.
For a start, its just only for one user.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I have recommended this question be closed as follows:
Accept: Senior IT System Engineer (https:#a41841121)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
exchangepro
Experts-Exchange Cleanup Volunteer
I have recommended this question be closed as follows:
Accept: Senior IT System Engineer (https:#a41841121)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
exchangepro
Experts-Exchange Cleanup Volunteer
1. Start Windows PowerShell ISE
2. Type gci -path c:\ -recurse -include *.pst|select-object fullname,lastwritetime|exp
3. Wait until the script finishes
In this case the output is sent to a csv file in the c:\temp folder.
OR you can use the script below:
$strComputers = Get-Content -Path "C:\computernames.txt"
[bool]$firstOutput = $true
foreach($strComputer in $strComputers)
{
$colFiles = Get-Wmiobject -namespace "root\CIMV2" `
-computername $strComputer `
-Query "Select * from CIM_DataFile `
Where Extension = 'pst'"
foreach ($objFile in $colFiles)
{
if($objFile.FileName -ne $null)
{
$filepath = $objFile.Drive + $objFile.Path + $objFile.FileName + "." `
+ $objFile.Extension;
$query = "ASSOCIATORS OF {Win32_LogicalFileSecurity
+ $filepath `
+ "'} WHERE AssocClass=Win32_LogicalFi
$colOwners = Get-Wmiobject -namespace "root\CIMV2" `
-computername $strComputer `
-Query $query
$objOwner = $colOwners[0]
$user = $objOwner.ReferencedDomain
$output = $strComputer + "," + $filepath + "," + $user + "," + $objFile.FileSize/1KB + "," + $objFile.LastModified
if($firstOutput)
{
Write-output $output | Out-File -Encoding ascii -filepath "C:\pstdetails.csv"
$firstOutput = $false
}
else
{
Write-output $output | Out-File -Encoding ascii -filepath "C:\pstdetails.csv" -append
}
}
}
}