How do I select printer from printserver and connect it? What is the right way to do that?
This code works but how to write better code without creating temporary variable $x ?
$x = Get-Printer -ComputerName print-server | Out-GridView -PassThru -Title "Select printer to connect" | Select @{n="ConnectionName";e={"\\$($_.ComputerName)\$($_.Name)"}} | Select -ExpandProperty ConnectionName
Add-printer -ConnectionName $x
PS: Now I did it like this. If somebody can do better feel free to propose an answer.
Get-Printer -ComputerName print-server |
Sort-Object |
Out-GridView -PassThru -Title "Select printer to connect" |
Select @{n="ConnectionName";e={"\\$($_.ComputerName)\$($_.Name)"}} |
ForEach-Object {Add-Printer -ConnectionName $_.ConnectionName}
The following code:
Out-GridView
to allow user to select the desired printer(s).Get-Printer -ComputerName 'print-server.domain.com' |
Where-Object {$_.Name -match '(?i)PL.*'} |
Sort-Object |
Out-GridView -PassThru -Title 'Select printer to connect' |
Foreach-Object { Add-Printer -ConnectionName ('\\{0}\{1}' -f $_.ComputerName, $_.Name) }