how to search for a.bak files on all drives on multiple computers

siva k
siva k used Ask the Experts™
i have 10 computeers and saved .bak files almost in all drives.

i am using below script to find .bak  but not getting the result.

#server.txt contains computer names

$comp=get-content d:servers.txt

foreach($comp in $comp)

$k=Get-ChildItem d:\*,c:\* -recurse -include *.bak

$k|select fullname | Export-Csv C:\files.csv -NoTypeInformation

please help me.............
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
You're never accessing a remote machine.
Try this; it queries each local disk on the remote machines:
Get-Content -Path D:\servers.txt | ForEach-Object {
	$Server = $_
	"Processing $($Server)" | Write-Host
	Try {
		Get-WmiObject -Query "SELECT Name FROM Win32_LogicalDisk WHERE DriveType=3" -ComputerName $Server -ErrorAction Stop | ForEach-Object {
			"  - Drive $($_.Name)" | Write-Host
			Get-ChildItem "\\$($Server)\$($_.Name.Replace(':', '$'))" -Filter *.bak -Recurse -ErrorAction Continue |
				Select-Object -Property @{n='ComputerName'; e={$Server}}, @{n='DirectoryName'; e={$_.DirectoryName.Split('\', 4)[3].Replace('$', ':')}}, Name, Length, LastWriteTime
	} Catch {
		"Unable to access $($Server): $($_.Exception.Message)" | Write-Error
} | Export-Csv -Path C:\files.csv -NoTypeInformation

Open in new window

Most Valuable Expert 2018
Distinguished Expert 2018

Question answered.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial