Scenario
You want to check to see if a file exists on a bunch of remote computers...Script
#==========================================================================
#
# Check Computers to see which ones have a specified file.
#
# AUTHOR: Matthew Graham
# DATE : 09/04/2019
#
# Change log:
# -----------
# 09/04/2019 Matthew Graham: Initial Creation of script
#
#==========================================================================
# Import Computers you want to check
$computerlist = Get-Content C:\TEMP\EclipseSearch\computerlist.csv
$ResultPath = "C:\TEMP\EclipseSearch"
# Loop through computers to see if the file exists.
foreach ($machine in $computerlist){
$searchpath = "\\$machine" + "\C$\Program Files\Eclipse2019-06\eclipse.exe"
$EclipseExists = Test-Path -Path $searchpath
If ($EclipseExists -eq $true)
{
Write-Host "Computer $machine has Eclipse" -ForegroundColor Green
$machine | Out-File $ResultPath\FileExists.txt -Append
}
Else
{
Write-Host "Computer $machine does not have Eclipse" -ForegroundColor Red
$machine | Out-File $ResultPath\FileDoesNotExist.txt -Append
}
}
#
# Check Computers to see which ones have a specified file.
#
# AUTHOR: Matthew Graham
# DATE : 09/04/2019
#
# Change log:
# -----------
# 09/04/2019 Matthew Graham: Initial Creation of script
#
#==========================================================================
# Import Computers you want to check
$computerlist = Get-Content C:\TEMP\EclipseSearch\computerlist.csv
$ResultPath = "C:\TEMP\EclipseSearch"
# Loop through computers to see if the file exists.
foreach ($machine in $computerlist){
$searchpath = "\\$machine" + "\C$\Program Files\Eclipse2019-06\eclipse.exe"
$EclipseExists = Test-Path -Path $searchpath
If ($EclipseExists -eq $true)
{
Write-Host "Computer $machine has Eclipse" -ForegroundColor Green
$machine | Out-File $ResultPath\FileExists.txt -Append
}
Else
{
Write-Host "Computer $machine does not have Eclipse" -ForegroundColor Red
$machine | Out-File $ResultPath\FileDoesNotExist.txt -Append
}
}
The script gets the content of a file containing a list of computers you want to check. It outputs to the PowerShell host to tell you if it found the file or not. Then it creates two files "File Exists" and "File Does Not Exist" in the Resultpath.
Use at your own risk.
No comments:
Post a Comment