Hi all,<\/p>\n
I have the follwing script that goes at and hunts for files of a certain type on remote computers and stores them in a folder. It reads in PC names and username from a spreadsheet (.CSV).<\/p>\n
I want to adapt it so that is only searches the user profile, not the entire C: drive.<\/p>\n
So the line is:<\/p>\n
$fileList = Get-WmiObject -Class CIM_DataFile -Filter \"Drive='C:' And Extension='dic'\" -Computername $computerName\n<\/code><\/pre>\nI’d like to change is to that it has something like Path=C:\\users$userName and searched that whole set of subfolders.<\/p>\n
I can’t for the life of me figure out how to make it work. I keep getting invalid queries when I try to add a path.<\/p>\n
Entire Script follows:<\/p>\n
$computerName = @()\n$userName = @()\n\nImport-Csv C:\\test\\script\\Computername_username_test.csv |`\n\tForEach-Object {\n\t\t\t$computerName = $_.ComputerName\n\t\t\t$userName = $_.UserName\n\n$fileList = Get-WmiObject -Class CIM_DataFile -Filter \"Drive='C:' And Extension='dic' AND Path='c:\\users\\$userName'\" -Computername $computerName\n$destination = New-Item -ItemType Directory -Path C:\\test\\$userName\\dictionary_Files\\ -force \n\n foreach ($file in $fileList)\n {\n\t $drive, $path = $file.Name.Split('\\',2)\n\t $drive = $drive -replace ':','$'\n $remoteFile = \"\\\\$computerName\\$drive\\$path\"\n $FileName = ($path -split \"\\\\\")[-1] -replace \".dic\"\n $destFileName = $FileName\n $count = 0\n While (Test-Path -Path \"$destination\\$destFileName.dic\") {\n $count++\n $destFileName = \"$FileName\"+\"$count\"\n }\n\t Write-Verbose \"Copy $remoteFile to $destination\\$destFileName.dic\"\n\t Copy-Item $remoteFile -Destination \"$destination\\$destFileName.dic\" \n }\n}\n<\/code><\/pre>\nThank you all very much for any help you can provide!<\/p>\n