I have a list of computers (.txt file) that I need to see if a directory exist under each user profile, then output to csv with computer name, profile name and true/false.
Text file location: C:\temp\scripts\bluezoneexist.txt
Looking for this directory C:\users%profile%\documents\bluezone
Output contains: Machine name, Profile name, True/False
Output location: C:\temp\scripts\bluezoneexist.csv
So I have written previous scripts to look at a list of computers to see if a directory exist in Program Files and output the results:
#This file contains the list of machines you want to use $computers = gc "C:\scripts\O365PathExist.txt" #output file name and location $outfile = "C:\scripts\O365PathExist.csv" #removes existing output file if it exist If(Test-Path $outfile){Remove-Item $outfile -Force} #this pulls from the list of computers, looks to see if Office path exist and outputs results. If machine is off it will show as False foreach ($computers in $computers) { $content = Test-Path -path "\\$computers\c$\Program Files (x86)\Microsoft Office\root" $content2 = Test-Path -path "\\$computers\c$\Program Files\Microsoft Office\root" "$computers, $content, $content2" | Add-Content $outfile }
And I have written scripts that looks at all user profiles on a single computer to see if a directory exist and output the results (profile name, true/false):
$outfile = "C:\temp\scripts\bluezone2.csv" $paths = Get-ChildItem -Directory c:\users | Select-Object $_.Name
ForEach ($path in $paths){ $content = test-path -path "c:\users\$path\Documents\BlueZone" "$path, $content" | Add-Content $outfile }
I tried this and it goes through the list of machines and outputs correctly, but the user profiles are from the machine in which I run it on and not the profiles from the list of machines:
#This file contains the list of machines you want to use $computers = gc "C:\temp\scripts\BlueZoneExist.txt" #output file name and location $outfile = "C:\temp\scripts\BlueZoneExist.csv" #removes existing output file if it exist If(Test-Path $outfile){Remove-Item $outfile -Force} #search user profiles $paths = Get-ChildItem -Directory c:\users | Select-Object $_.Name foreach ($computers in $computers) {ForEach ($path in $paths){ $content = test-path -path "c:\users\$path\Documents\BlueZone" "$computers, $path, $content" | Add-Content $outfile } }
But I cannot figure out how I can pull from a list of computers and loop through all user profiles on those computers to see if a directory exist and then output the results to a csv…