Invoke-Command not working for executing another script using UNCPath?
Posted: Thu Feb 07, 2019 10:27 pm
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:
This is the error code:
When I run with just one simple line below:
It is still failed with the error:
I wonder if this is even possible to achieve or not?
Thank you in advance.
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
Code: Select all
Access is denied
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
Code: Select all
Invoke-Command -ComputerName 'SITE1WKS' -ScriptBlock {\\mydomain.com\netlogon\Script\LogonScript-v4.BAT}
Code: Select all
An error occurred while creating the pipeline.
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
+ PSComputerName : SITE1WKS
Thank you in advance.