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

**URL:** <https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057>\
**Category:** PowerShell Help\
**Created:** [August 24, 2016, 4:55am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057 "2016-08-24T04:55:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul-nair](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@rahul-nair](https://forums.powershell.org/u/rahul-nair)\
**Post date:** [August 24, 2016, 4:55am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/1 "2016-08-24T04:55:21Z")

</div>

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

$CompName = “[test.domain.com](http://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](http://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)”

---

<div class="post-metadata">

**Author:** ![jonathan-warnken](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jonathan-warnken/32/469_2.png) [@jonathan-warnken](https://forums.powershell.org/u/jonathan-warnken)\
**Post date:** [August 24, 2016, 5:21am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/2 "2016-08-24T05:21:14Z")

</div>

It sounds as though you are having a issue with the second hop to the printer. Even though your pssession example is using Credssp there are several steps to ensure it is working. I would recommend reviewing the Second Hop section of “Secrets of PowerShell Remoting” (available for free from the eBooks section of this site)

A quick test to verify the second hop is working is to connect to the remote system and do a dir against another system.

```
Get-ChildItem \\SomeSystem\SomeShare
```

---

<div class="post-metadata">

**Author:** ![rahul-nair](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@rahul-nair](https://forums.powershell.org/u/rahul-nair)\
**Post date:** [August 24, 2016, 5:48am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/3 "2016-08-24T05:48:32Z")

</div>

Hi, I have already tested WinRM connectivity and access to remote server etc.  
I can even run other powershell or batch file in remote machine. Issue is only with adding printer.

---

<div class="post-metadata">

**Author:** ![jonathan-warnken](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jonathan-warnken/32/469_2.png) [@jonathan-warnken](https://forums.powershell.org/u/jonathan-warnken)\
**Post date:** [August 24, 2016, 9:05pm UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/4 "2016-08-24T21:05:47Z")

</div>

The issue is not connectivity to the remote server it is passing authenticating on the next hop. In this case the print server.

For example this should work for you

```
Invoke-Command -ComputerName Server1 -ScriptBlock {Get-ChildItem c:\}
```

But this will fail

```
Invoke-Command -ComputerName Server1 -ScriptBlock {Get-ChildItem \\Server2\admin`$}
```

If credssp is configured on all systems correctly then this would work

```
Invoke-Command -ComputerName Server1 -ScriptBlock {Get-ChildItem \\Server2\admin`$} -Authentication Credssp
```

If it fails then at least one system is not setup for Credssp delegation. Both the system initiating the connection and the intermediary server must be configured.

---

<div class="post-metadata">

**Author:** ![rahul-nair](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@rahul-nair](https://forums.powershell.org/u/rahul-nair)\
**Post date:** [August 25, 2016, 1:50am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/5 "2016-08-25T01:50:37Z")

</div>

# **Working without Credssp**  
Invoke-Command -ComputerName [remotemac.mydomain.com](http://remotemac.mydomain.com) -ScriptBlock {Get-ChildItem C:\Users\myusername\Desktop}  
# **Working with CredSSP**  
Invoke-Command -ComputerName [remotemac.mydomain.com](http://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](http://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](http://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?  
please suggest.

---

<div class="post-metadata">

**Author:** ![jonathan-warnken](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jonathan-warnken/32/469_2.png) [@jonathan-warnken](https://forums.powershell.org/u/jonathan-warnken)\
**Post date:** [August 25, 2016, 11:41am UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/6 "2016-08-25T11:41:41Z")

</div>

you can deploy the script via Group Policy as a logon script

---

<div class="post-metadata">

**Author:** ![rahul-nair](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@rahul-nair](https://forums.powershell.org/u/rahul-nair)\
**Post date:** [August 25, 2016, 11:50pm UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/7 "2016-08-25T23:50:38Z")

</div>

Can you give any samples or url having samples

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/adding-printer-in-remote-machine-is-not-working-invalid-printer-name/7057/8 "2024-05-16T20:40:38Z")

</div>


