Checking to see if a folder exists on Hidden Drive

I’ve got a script to check if a folder exists on a drive for a list of servers. The script works as expected for drives that are visible e.g. C:.
The problem I have is I’m trying to use the script to check if a folder exists on a list of servers (Citrix servers) on their D partition. The problem I have is that the D partition is hidden via policy. Hence why the script does NOT work. I’m guessing this is pretty unique but just wondering if there’s a way to get this to work for a hidden drive?
Script:

$ServerList = Get-Content “C:\PS\Servers.txt”
$path = “D:\EventLogs”

foreach ($server in $ServerList) {

$Test = (Test-Path -Path $path)

If ($Test -eq $True) {Write-Host “Folder Exists on $Server”}

else

{Write-Host “Folder Does Not Exist on $Server”

}

Kerry,
Welcome to the forum. :wave:t4:

Please when you post code use the preformetted text button ( </> ) to format it as code. Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance.

You do not check the existence of the folders on different servers with your code you check the existence of a local folder on your machine as many times as you have servers in your input file. :wink:

You can either use remoting like this:

$ServerList = Get-Content 'C:\PS\Servers.txt'
Invoke-Command -ComputerName $ServerList -ScriptBlock {
    If (Test-Path -Path 'D:\EventLogs') { 
        Write-Host "Folder exists on '$($ENV:ComputerName)'" 
    }
    else {
        Write-Host "Folder does not exist on '$($ENV:ComputerName)'" 
    }
}

or you simply use the administrative shares to access the desired folders like this:

$ServerList = Get-Content 'C:\PS\Servers.txt'
foreach ($server in $ServerList) {
    $Path = '\\{0}\d$\EventLogs' -f $server
    If (Test-Path -Path $path) { 
        Write-Host "Folder exists on '$($server)'" 
    }
    else {
        Write-Host "Folder does not exist on '$($server)'" 
    }
}

Thank you so much Olaf!!!
Very much appreciated!