Good morning,<\/p>\n
I’m in need of searching our network for all pst files with the location, size, last modified and system name. I came across the following script, but I am having issues getting it to work correctly. It doesn’t gather information for all systems in the text file, it will run but only export information for the last system in the text file. Any help would be greatly appreciated!<\/p>\n
$Computers = Get-Content -Path “C:\\Comps.txt” #$Owner = @(Get-Wmiobject -namespace “root\\CIMV2” -computername $Computer -Query $query) Thanks!<\/p>","upvoteCount":2,"answerCount":6,"datePublished":"2019-03-06T15:53:43.000Z","author":{"@type":"Person","name":"spiceuser-iy7ut","url":"https://community.spiceworks.com/u/spiceuser-iy7ut"},"acceptedAnswer":{"@type":"Answer","text":" Having this line<\/p>\n $output = @()<\/p>\n Inside the foreach loop causes it to reset for each computer. It needs moved above the foreach.<\/p>","upvoteCount":0,"datePublished":"2019-03-06T23:13:10.000Z","url":"https://community.spiceworks.com/t/powershell-script-find-pst-files-on-network/700842/6","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},"suggestedAnswer":[{"@type":"Answer","text":" Good morning,<\/p>\n I’m in need of searching our network for all pst files with the location, size, last modified and system name. I came across the following script, but I am having issues getting it to work correctly. It doesn’t gather information for all systems in the text file, it will run but only export information for the last system in the text file. Any help would be greatly appreciated!<\/p>\n $Computers = Get-Content -Path “C:\\Comps.txt” #$Owner = @(Get-Wmiobject -namespace “root\\CIMV2” -computername $Computer -Query $query) Thanks!<\/p>","upvoteCount":2,"datePublished":"2019-03-06T15:53:43.000Z","url":"https://community.spiceworks.com/t/powershell-script-find-pst-files-on-network/700842/1","author":{"@type":"Person","name":"spiceuser-iy7ut","url":"https://community.spiceworks.com/u/spiceuser-iy7ut"}},{"@type":"Answer","text":" Welcome<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
\nForeach ($Computer in $Computers)
\n{
\n$PstFiles = Get-Wmiobject -namespace “root\\CIMV2” -computername $Computer -Query “Select * from CIM_DataFile
\nWhere Extension = ‘pst’”
\n$output = @()
\nforeach ($file in $PstFiles)
\n{
\nif($File.FileName)
\n{
\n$pstinfo = “” | select Computer, Path, FileSize, LastModified, LastAccessed
\n$filepath = $file.description
\n$query = “ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=' $filepath<\/code>
\n'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner”<\/p>\n
\n#$Owner = $Owner[0]
\n$pstinfo.Computer = $Computer
\n$pstinfo.Path = $filepath
\n$pstinfo.FileSize = $file.FileSize/1GB
\n#$pstinfo.Owner = “$($Owner.ReferencedDomainName)$($Owner.AccountName)”
\n$pstinfo.LastModified = [System.Management.ManagementDateTimeConverter]::ToDateTime($($file.LastModified))
\n$pstinfo.LastAccessed = [System.Management.ManagementDateTimeConverter]::ToDateTime($($file.LastAccessed))
\n$output += $pstinfo
\n}
\n}
\n}
\n$output | Export-Csv c:\\pstdetails.csv -NoClobber -NoTypeInformation<\/p>\n
\nForeach ($Computer in $Computers)
\n{
\n$PstFiles = Get-Wmiobject -namespace “root\\CIMV2” -computername $Computer -Query “Select * from CIM_DataFile
\nWhere Extension = ‘pst’”
\n$output = @()
\nforeach ($file in $PstFiles)
\n{
\nif($File.FileName)
\n{
\n$pstinfo = “” | select Computer, Path, FileSize, LastModified, LastAccessed
\n$filepath = $file.description
\n$query = “ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=' $filepath<\/code>
\n'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner”<\/p>\n
\n#$Owner = $Owner[0]
\n$pstinfo.Computer = $Computer
\n$pstinfo.Path = $filepath
\n$pstinfo.FileSize = $file.FileSize/1GB
\n#$pstinfo.Owner = “$($Owner.ReferencedDomainName)$($Owner.AccountName)”
\n$pstinfo.LastModified = [System.Management.ManagementDateTimeConverter]::ToDateTime($($file.LastModified))
\n$pstinfo.LastAccessed = [System.Management.ManagementDateTimeConverter]::ToDateTime($($file.LastAccessed))
\n$output += $pstinfo
\n}
\n}
\n}
\n$output | Export-Csv c:\\pstdetails.csv -NoClobber -NoTypeInformation<\/p>\n