1. Create folder - "Logs" - file - TestPath.logs
2. Create .csv file for input - testPath.csv , column name should be - "FileSharePath"
3. Create .ps1 file and write below script
4. It will give output csv file with columns FileShrePath, Status, Date, Time
#Input file should be .csv file format, and column name should be - "FileSharePath"
#############################################################################
#Provide the input and output file path
$CSVPath ="D:\TestPath.csv"
$Logfile = "D:\Logs\TestPath.log"
$outputFilePath = "D:\TestPath_result1.csv"
#############################################################################
$data = @()
$status = ""
#checking given input .csv path is correct or not
if (Test-Path $CSVPath)
{
$csvContent = Import-Csv -Path $CSVPath
foreach($row in $csvContent)
{
if (Test-Path $row.FileSharePath)
{
#Write-Host $row.FileSharePath "is a valid path" -foregroundcolor "Green"
#LogWrite $row.FileSharePath "is a valid path"
try
{
if(ACL $row.FileSharePath)
{ Write-Host $row.FileSharePath " - Access is there" -foregroundcolor "Green"
LogWrite ($row.FileSharePath +" - Access is there")
$status = "Access is there"
}
}
catch
{
Write-Host $row.FileSharePath " - Access Denied" -foregroundcolor "Red"
LogWrite ($row.FileSharePath +" - Access Denied")
$status = "Access Denied"
}
}
else
{
Write-Host $row.FileSharePath " - invalid path" -foregroundcolor "Red"
LogWrite ($row.FileSharePath +" - invalid path")
$status = "invalid path"
}
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name 'FileSharePath' -Value $row.FileSharePath
$object | Add-Member -MemberType NoteProperty -Name 'Status' -Value $status
$object | Add-Member -MemberType NoteProperty -Name 'Date' -Value (get-date -Format dd-MM-yyyy)
$object | Add-Member -MemberType NoteProperty -Name 'Time' -Value (get-date -Format HH:mm:ss)
$data += $object
}
#Export to CSV file
$data | Export-Csv $outputFilePath -NoTypeInformation -Append
Write-Host ""
Write-Host "Output file is availabe - " $outputFilePath -foregroundcolor "Yellow"
Read-Host -Prompt "Please press enter to exit..."
}
else
{
Write-Host $CSVPath " - invalid input .csv file path" -foregroundcolor "Red"
LogWrite ($row.FileSharePath +" - invalid input .csv file path")
}
function LogWrite
{
param([string]$logstring)
$dateTime = get-date -format G
#Write-Host " "
#Write-Host $dateTime $logstring
Add-Content $Logfile -Value " "
Add-Content $Logfile -Value ( $dateTime + $logstring)
}
