Page 1 of 1

Invoke-Command not working for executing another script using UNCPath?

Posted: Thu Feb 07, 2019 10:27 pm
by ITEngineer
Hi All People,

I need some help to execute the Batch script remotely using Invoke-Command but still failed numerous times.

I have executed the PowerShell ISE from my local workstation as Administrator and my user account is the member of Enterprise Administrator and Domain Admins group.

When I try to RDP into the system and then run the script manually \\mydomain.com\netlogon\Script\LogonScript-v4.BAT it works with no issue.

This is the script:

Code: Select all

$ADDomain = (Get-WmiObject Win32_ComputerSystem).Domain
$Computer = "SITE1WKS" + "." + $ADDomain
$session = New-PSSession -ComputerName $Computer
Invoke-Command -Session $session -ScriptBlock {
    Try {
        \\$ADDomain\netlogon\Script\LogonScript-v4.BAT
    }
    Catch {
        Write-Error $_
    }    
}
Remove-PSSession $session
This is the error code:

Code: Select all

Access is denied
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
When I run with just one simple line below:

Code: Select all

Invoke-Command -ComputerName 'SITE1WKS' -ScriptBlock {\\mydomain.com\netlogon\Script\LogonScript-v4.BAT}
It is still failed with the error:

Code: Select all

An error occurred while creating the pipeline.
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
    + PSComputerName        : SITE1WKS
I wonder if this is even possible to achieve or not?

Thank you in advance.

Re: Invoke-Command not working for executing another script using UNCPath?

Posted: Thu Feb 07, 2019 11:24 pm
by jvierra
"Second hop restriction" You cannot access a third computer from a remote session.

Re: Invoke-Command not working for executing another script using UNCPath?

Posted: Sun Feb 10, 2019 3:56 pm
by ITEngineer
jvierra wrote: Thu Feb 07, 2019 11:24 pm "Second hop restriction" You cannot access a third computer from a remote session.
OK, so how to make it working?

Re: Invoke-Command not working for executing another script using UNCPath?

Posted: Sun Feb 10, 2019 5:11 pm
by jvierra
Use CredSSP which has to be configured on both ends.