I am trying to read a list of computers from a .txt file, then look for a specific file named engage.* that exists in a specific directory on the pcs, then output the file info for engage.* to a csv file. However, when using the $computer variable in the get-childitem command, no data is outputted. Here is my script:
$computers = Get-Content -Path \scripts\pclist.txt
foreach ($computer in $computers){
Get-ChildItem -path "\\$computer\C$\Pfx Engagement\WM\Workpapers\*\engage.*" |
export-csv "c:\scripts\engage3.csv" -notypeinformation -encoding utf8
}
If I test by running the script for a specific pc name, it works great and outputs the file info to the .csv file:
Get-ChildItem -path "\\0543834Laptop\C$\Pfx Engagement\WM\Workpapers\*\engage.*" |
export-csv "c:\scripts\engage2.csv" -notypeinformation -encoding utf8
The get-childitem cmd does not like using the $computer variable in the foreach loop. I cannot find anything after hrs of research that says you cannot use a variable in the get-childitem cmd. Is there something obvious I'm overlooking here? thanks for any suggestions.
hrs of googling and editing my code.