- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to test the shared location path from the remote computer in PowerShell?
Many times we need to test the NAS path or shared path location from the remote server. Meaning we need to check if the shared path is accessible from the remote location and we use the Test-Path that time but we get an error of PermissionDenied or UnauthorizedAccessExcept.
Our sample code is shown below and in this example, we are using the Invoke-Command to connect to another computer and from there we are checking if the shared path is accessible.
Example
Invoke-Command -ComputerName LabMachine2k16 -ScriptBlock { Test-Path -Path "\ad\Shared\Temp" }
This script throws an exception.
Output
Access is denied + CategoryInfo : PermissionDenied: (\ad\Shared\Temp:String) [Test-Path], UnauthorizedAccessException + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand + PSComputerName : LabMachine2k16 False
This is not the permission issue but this is a PowerShell remoting issue. By default PowerShell remoting supports one layer of remoting, here we are connecting to a remote machine and again checking the shared path from it so it becomes the 2 stages of remoting and PowerShell doesn't support it.
To get this issue solved, we can use the Map drive to test if we can connect to it successfully or not. If yes then the remote server has connectivity to that path. For example,
Example
Invoke-Command -ComputerName LabMachine2k16 -ScriptBlock{ if(New-PSDrive -Name X -PSProvider FileSystem ` -Root "\Ad\Shared\Temp" -EA Ignore){ Write-Output "Path is accessible" } }
Output
Path is accessible
- Related Articles
- How to test remote computer connectivity using PowerShell?
- How to copy files/folders to the remote location in the PowerShell?
- Difference between Test-Path and Resolve-Path in PowerShell?
- How to copy items from one location to another location using PowerShell?
- How to get the Shared folder permissions with PowerShell?
- How to Remove the computer from the AD domain using PowerShell?
- How to use the Set-Location command in PowerShell?
- How to get the list of shared folders using PowerShell?
- How to use Push-Location and Pop-Location command in PowerShell?
- How to check the PowerShell version installed in local and remote systems?
- How to get all the processes on remote computers using PowerShell?
- How to restart a remote system using PowerShell?
- How to validate the path with the PowerShell function parameter?
- How to get services on remote computers with PowerShell?
- How to get the path of the currently executing script in PowerShell?
