Hi All,
I was hoping someone could help me out with a little problem I'm having.
I need to run the test-path cmdlet on a DFS Namespace UNC, but I also need to run it with alternate credentials.
Problem is, the test-path cmdlet doesn't support the -Credental parameter, so I'm trying to wrap it up in an Invoke-Command cmdlet.
For some reason, I keep getting an access denied error returned. I know for a FACT that the account I'm using for the alternate creds has permissions here because when I open a powershell prompt as that user, it works fine.
The invoke-command wrapper works too if I'm using a local path (C:\path\folder), but not with a DFS UNC. Here's my code:
$targ = "filesystem::\\domain.com\FakePath\FakeFolder" $username = "FakeUser" $password = ConvertTo-SecureString "FakePassword" -AsPlainText -Force $cred = new-object System.Management.Automation.PSCredential ($username, $password) $tp = Invoke-Command -ComputerName "." -Credential $cred -ScriptBlock {test-path $args[0]} -ArgumentList $targ if ($tp -eq $false) {Write-host "Cannot find folder!"} if ($tp -eq $true) {Write-host "Found folder!"}
Here's the error it's returning:
ERROR: Access is deniedERROR: + CategoryInfo : PermissionDenied: (\\domain.com\fakepath\fakefolder:String) [Test-Path], UnauthorizedAccessException
ERROR: + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand
ERROR: + PSComputerName : localhost
Any ideas?
Thanks,
Chris
- Edited by Topher2798 11 hours 35 minutes ago