My very rudimentary script does not out put the results of the query to a file.
I've tried Out-File, Export-CSV. Sometimes a file is written, but it doesn't contain any data. Its just blank.
And I believe write-host is something I should not be using, but am not skilled enough to know how i SHOULD be dealing with powershell results.
# Read input file of computer names and paths
$computers = Get-Content C:\temp\test-path-test.txt
$paths = Get-Content C:\temp\test-path-test-paths.txt
# Nested Loop through each computer name in the array, and each path
foreach ($computer in $computers) {
foreach ($path in $paths) {
$exists = Test-Path "\\$computer\$path"
If ($exists -eq $true ) { Write-Host $computer, $path, 'This Path Exists'}
Else { Write-Host $computer, $path 'Path Not Found' }
}
}
I was hoping it would output a csv file of ComputerName,Path, and whether the path exists or not.
Can anyone shed any light on how I can better output the results of this to a file?