adding printer in remote machine is not working: invalid printer name

0

I have gone through many blogs for finding solution for this issue, but never find a solution.

$CompName = "test.domain.com"
$Printer = "\\122.21.10.11\PRINTER-NAME-1"
Invoke-Command -ComputerName $CompName -Scriptblock {
  Param($p)
  (New-Object -Com Wscript.Network).AddWindowsPrinterConnection($p)
} -ArgumentList $Printer

I have even tried PSRemoting and tried to execute the ps1 file from remote machine. the same script is working in local and not working remote.

Enter-PSSession -ComputerName "testserver.testdomain.com" -Authentication Credssp -Credential Get-Credential

Error:

Exception calling "AddWindowsPrinterConnection" with "1" argument(s): "The printer name is invalid. (Exception from HRESULT: 0x80070709)"

Updates:

Working without CredSSP:

Invoke-Command -ComputerName remotemac.mydomain.com -ScriptBlock {
  Get-ChildItem C:\Users\myusername\Desktop
}

Working with CredSSP:

Invoke-Command -ComputerName remotemac.mydomain.com -ScriptBlock {
  Get-ChildItem \\sharedmac\sharef
} -Authentication Credssp -Credential mydomain\myusername

Script is working, but not showing network printers:

Invoke-Command -ComputerName remotemac.mydomain.com -ScriptBlock {
  (New-Object -ComObject WScript.Network).EnumPrinterConnections()
} -Authentication Credssp -Credential mydomain\myusername

Script gives error: Invalid Printer name

$Printer = "\\172.26.30.13\SDB1-FLOOR1-B2" # I have tried this input in single, double, with and without escape character
Invoke-Command -ComputerName remotemac.mydomain.com -ScriptBlock {
  Param($p)
  (New-Object -Com WScript.Network).AddWindowsPrinterConnection("$p")
} -ArgumentList $Printer -Authentication Credssp -Credential mydomain\myusername

I'm totally stuck.

I heard we can use Group Policy, is there anyway we can automate this using group policy?

powershell
remoting
network-printers
asked on Stack Overflow Aug 24, 2016 by Rahul Nair • edited Aug 25, 2016 by Ansgar Wiechers

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0