test-path fails to access remote drive on certain systems

This topic contains 6 replies, has 3 voices, and was last updated by Profile photo of Don Smith Don Smith 2 weeks, 3 days ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #53773
    Profile photo of Don Smith
    Don Smith
    Participant

    hello,
    I have a script I use to determine if certain logs are present on various remote systems. This script works fine on most systems.
    However on certain systems the test-path commandlet fails to access the C$ drive on the remote system.
    It isn't the command itself or it would fail universally across all of the systems I test.

    I have looked at the executionPolicy on the remote systems to see if that might be what is preventing the powershell script from running on the remote system but it doesn't seem to play a role in the failures.

    I use the same credentials when I RDP into the remote system and I can traverse the directories and see that the logs are present. This should eliminate the issue of whether the script is being run with sufficient privileges to access the remote drive.

    Could someone please enlighten me as to why powershell can not access the remote drive when using the following command?
    I am assuming it is a permissions issue or a powershell configurable parameter issue but I have no clue as to which parameter it might be.

    $strTargetHost='serverA' #serveA exists and is online.

    if (! (Test-Connection $strTargetHost) ) {
    write-host "Couldn't ping server"
    }
    else {
    if (!(Test-Path "\\$strTargetHost\C$\")) {
    write-host "Can't access C$..."
    }
    else {
    #gather the logs...
    }
    }

    Thanks in advance,
    Don

    #53777
    Profile photo of 84rusty .
    84rusty .
    Participant

    Is the firewall enabled on the remote systems? You may be blocking SMB.

    Is UAC enabled on the remote systems?

    Can you ping the remote systems?

    Are you able to access the share on the actual remote machines themselves? e.g. \\localhost\c$

    Is Remote Registry service enabled on the remote systems?

    You can confirm the shares are 'there' by running 'net share' at command prompt

    Also, you don't need the extra slash on the end:
    if (!(Test-Path "\\$strTargetHost\C$\")) {
    can be changed to
    if (!(Test-Path "\\$strTargetHost\C$")) {

    #53781
    Profile photo of Don Jones
    Don Jones
    Keymaster

    And note that ExecutionPolicy on the remote system doesn't matter, as the remote system isn't being asked to run PowerShell at all. On those systems where you encounter a problem, a good troubleshooting step would be to see if you can hit Windows+R on your keyboard, type the same (failing) path, and get a result or not. If you do, that eliminates a whole slew of potential causes. If you don't, then PowerShell isn't anywhere near the problem.

    #53974
    Profile photo of Don Smith
    Don Smith
    Participant

    Is the firewall enabled on the remote systems? You may be blocking SMB.
    The systems should be configured universally throughout the enterprise. This script works on most of the systems.
    Only on a few, mostly a few of the older systems we are phasing out (2003) but this one was a 2012 R2 server so that
    indicated to me that this wasn't a compatibility issue.

    Is UAC enabled on the remote systems?
    Yes we use UAC for to prevent certain programs from running, but like I said this script works on the vast majority of
    our systems. Only a few 'malcontents' refuse to all me access with these credentials while using powershell. I can RDP
    into the exact system using the same credentials I used when running the ISE. So I know the credentials are accepted.

    Can you ping the remote systems?
    yes, I can even RDP into them using the same credentials I was using when I am running the script on a different system.

    Are you able to access the share on the actual remote machines themselves? e.g. \\localhost\c$
    On the vast majority of systems that fail, no I can't. On the systems that I can access yes I can access the share in this fashion. There was a single system that I was able to access in this fashion yet still unable to gather the logs from the system.

    Is Remote Registry service enabled on the remote systems?
    Auto (trigger start) or set to automatic.

    You can confirm the shares are 'there' by running 'net share' at command prompt
    yes, the shares are present, especially since this is the default share (C$), but I confirmed it anyways using the net share command.

    Any suggestions?
    Thanks in advance for your help.
    I do appreciate it.

    Don

    #53975
    Profile photo of Don Smith
    Don Smith
    Participant

    Note: the end backslash is present because this is actually a path for the log files. I have just backtracked to the share itself to see if I could access it or whether the problem was confined to the application file path.

    #53976
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, this:

    Are you able to access the share on the actual remote machines themselves? e.g. \\localhost\c$
    On the vast majority of systems that fail, no I can't. On the systems that I can access yes I can access the share in this fashion. There was a single system that I was able to access in this fashion yet still unable to gather the logs from the system.

    Is your problem. And this isn't a PowerShell problem, really – it's either firewall, permissions, account, or something else. This is just basic file sharing; once you solve this – so that you can open the system by just accessing the UNC from Explorer – PowerShell will work also.

    #53986
    Profile photo of Don Smith
    Don Smith
    Participant

    Thank you for your assistance. I will try to resolve the network issues.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.